我有一个 ListActivity
,我正在尝试从此布局文件中填充 Button
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/add_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/add_prop"
android:layout_alignParentBottom="true"
/>
</LinearLayout>
使用此代码:
View footer = getLayoutInflater().inflate(R.layout.footer, null);
ListView listView = getListView();
listView.setTextFilterEnabled(true);
listView.addFooterView(footer, null, false);
问题是,由于列表没有那么大,占据了整个屏幕(至少我认为这就是原因),因此按钮停留在列表的末尾,而不是粘在底部,因为 android:layout_alignParentBottom="true"
属性。我该怎么做才能让它粘在底部?
最佳答案
您必须使用以下代码创建一个新的布局文件:
<?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
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/add_button" />
<Button
android:id="@+id/add_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/add_prop"
android:layout_alignParentBottom="true" />
</RelativeLayout >
然后使用setContentView()
将其设置为Activity
的内容 View
关于java - 布局 Inflate 中的alignParentBottom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9098307/