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:
But when emulating it or loading it onto a phone, it looks like this:
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.
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
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.
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);
Changing the layout to RelativeLayout worked for me. Then added this line in viewPager tag :
android:layout_below="@id/appbar"
Voilla..!!
来源:https://stackoverflow.com/questions/33489430/android-studio-project-bottom-of-ui-is-cut-off