alignParentBottom在布局膨胀中

时间:2012-02-01 15:16:22

标签: java android layout

我有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);

问题在于,由于列表不是很大,占据了整个屏幕(至少我认为这就是原因)按钮停留在列表的末尾而不是坚持到底部因为{ {1}}财产。我该怎么做才能让它粘在底部?

1 个答案:

答案 0 :(得分:1)

您必须使用以下代码创建新的布局文件:

<?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的内容视图