这是我的 XML 布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true">
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1" />
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="2" />
</LinearLayout>
</RelativeLayout>
导致此问题的原因:
ListView 项目(红色轮廓)位于固定页脚后面,无法使用。有什么解决办法吗?
更新:
我更愿意被指出我的代码中的更改以解决该问题,然后进行某种解释。但这只是我的偏好。
最佳答案
我刚刚知道怎么做。通过利用 RelativeLayout
并将代码更改为:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/listview_footer"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true">
<EditText
android:id="@+id/new_task_title"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:hint="Add a new task" />
<Button
android:id="@+id/new_task_button"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="3"
android:text="+" />
</LinearLayout>
<ListView
android:id="@android:id/list"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/root"
android:layout_above="@id/listview_footer">
</ListView>
</RelativeLayout>
关于android - 固定页脚不显示最底部的列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4523328/