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

EGHM
  • 2,144
  • 23
  • 37
EmacsVI
  • 571
  • 1
  • 5
  • 15

5 Answers5

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.

sha
  • 1,410
  • 2
  • 18
  • 37
  • 1
    I changed the layout to Relative and set the ViewPager to be set below the appbar. Thanks for the tip! – EmacsVI Nov 03 '15 at 19:27
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

Community
  • 1
  • 1
Sherlock
  • 590
  • 7
  • 20
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.

Kosh
  • 6,140
  • 3
  • 36
  • 67
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);
Thomas R.
  • 7,988
  • 3
  • 30
  • 39
Krunal Patel
  • 61
  • 3
  • 12
0

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

android:layout_below="@id/appbar"

Voilla..!!

Yousha Arif
  • 111
  • 11