当我将我的应用程序加载到手机上或使用模拟器时,我的 ListView 和 ImageButton 的底部被切断时遇到问题。我可以只使用边距或填充,但这不是特定于设备的吗?无论屏幕尺寸如何,我都希望我的应用程序看起来像我想要的那样。这是我的代码:
类:
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 Studio 预览如下所示:
但是当模拟它或将它加载到手机上时,它看起来像这样:
最佳答案
这是因为您将 CoordinatorLayout
与 ListView
一起使用。您可以将实现更改为 RecyclerView
以实现正确的滚动。
或者如果你的目标是5.0以上,你可以使用下面的一段代码
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
listView.setNestedScrollingEnabled(true);
}
我认为 CoordinatorLayout
只适用于 NestedScrollingChild 的 child .
关于安卓工作室项目 : bottom of UI is cut off,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33489430/