Android Studio Project: bottom of UI is cut off
Asked Answered
P

5

5

I'm having a problem with the bottom of my ListView and ImageButton being cut off when I load my app onto a phone or when using an emulator. I could just use margins or padding, but wouldn't that be device specific? I'd like my app to look as I want it to regardless of screen size. Here is my code:

The Class:

public class Cookbook extends Fragment {

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        String[] items = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity().getApplicationContext(),
                        R.layout.row_layout,
                        items);

        View view = inflater.inflate(R.layout.frag_cookbook, container, false);
        ListView list = (ListView) view.findViewById(R.id.listView);
        list.setAdapter(adapter);


        return view;
    }
}

The Layout XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff">

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="fill"
        android:id="@+id/listView"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:background="#f9e48f" />

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_add"
        android:background="@null"
        android:layout_gravity="end|bottom"
        android:layout_alignParentBottom="true"
        android:baselineAligned="false"
        android:layout_alignParentEnd="true"
        android:layout_marginBottom="1dp" />


</RelativeLayout>

The Android Studio preview looks like this:

Android Studio Preview

But when emulating it or loading it onto a phone, it looks like this:

Emulated UI display

Privy answered 3/11, 2015 at 0:21 Comment(2)
It seems that the screenshots you've added are different, where the tabs came from?Lavonlavona
put your main activity xml where you push fragment fromMax
P
3

This is because you are using CoordinatorLayout with ListView. You can change your implementation to RecyclerView to achieve correct scroll.

or If you are tagetting above 5.0, you can use the following piece of code

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { listView.setNestedScrollingEnabled(true); }

I think CoordinatorLayout only works with the children of NestedScrollingChild.

Predictor answered 3/11, 2015 at 0:34 Comment(1)
I changed the layout to Relative and set the ViewPager to be set below the appbar. Thanks for the tip!Privy
I
0

I've had this happen to me before recently. I recommend posting your styles.xml as well.

The culprit for me was this line of code or something similar:

<item name="android:windowTranslucentStatus">true</item>

Here's the Question I posted with a similar issue: Layout is under StatusBar and Soft Keys

Impression answered 3/11, 2015 at 0:48 Comment(0)
J
0

In Android Design Library, well, the FloatingActionButton supposed to be within the CoordinatorLayout, not within any other views ex: a Fragment view in one of the tabs above. so try adding your FloatingActionButton to your main_layout and then just communicate with the activity to show/hide the FAB and do the necessary clicks.

Jaworski answered 3/11, 2015 at 1:44 Comment(0)
F
0

Put the below code in onCreateView, I think it will work.

View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
decorView.setSystemUiVisibility(uiOptions);
Flambeau answered 3/11, 2015 at 5:31 Comment(0)
C
0

Changing the layout to RelativeLayout worked for me. Then added this line in viewPager tag :

android:layout_below="@id/appbar"

Voilla..!!

Candent answered 7/9, 2018 at 18:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.