Android的Studio项目:用户界面的底部被切断 [英] Android Studio Project: bottom of UI is cut off
问题描述
我有我的ListView和ImageButton的底部的问题被切断时,我使用仿真器加载时,我的应用程序到手机或。我可以只使用保证金或填充,但是那不是特定于设备的?我想我的应用程序看起来像我希望它无论屏幕大小。这里是我的code:
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:
的类别:
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;
}
}
布局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>
Android的工作室preVIEW看起来是这样的:
The Android Studio preview looks like this:
但仿效,或将其加载到手机时,它看起来是这样的:
But when emulating it or loading it onto a phone, it looks like this:
推荐答案
这是因为你使用 CoordinatorLayout
与的ListView
。您可以将您的实现更改为 RecyclerView
来实现正确的卷轴。
This is because you are using CoordinatorLayout
with ListView
. You can change your implementation to RecyclerView
to achieve correct scroll.
或者如果你是tagetting 5.0以上,可以使用下面的一段code的
or If you are tagetting above 5.0, you can use the following piece of code
如果(Build.VERSION.SDK_INT&GT; = Build.VERSION_ codeS.LOLLIPOP){
listView.setNestedScrollingEnabled(真);
}
我觉得 CoordinatorLayout
只的 NestedScrollingChild 。
这篇关于Android的Studio项目:用户界面的底部被切断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!