2012-02-01 122 views
0

我有一个ListActivity,我试图夸大从这个布局文件ButtonalignParentBottom布局中的充气

<?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"属性,按钮停留在列表的最后,而不是坚持到底部。我该怎么做才能让它坚守底部?

+0

我不认为'机器人将它设置为Activity的内容视图:layout_alignParentBottom =“真” '在LinearLayout中有效果。它只适用于RelativeLayout。 – Vladimir 2012-02-01 15:22:20

+0

将'footer.xml'更改为'RelativeLayout'并且没有任何更改 – 2012-02-01 15:30:36

回答

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()

+0

但是我使用'ListActivity'来生成列表,而不是布局文件。如何在Java的布局文件上填充ListView? – 2012-02-01 18:20:36

+1

如果使用我的布局,那么'ListActivity'将自动使用布局文件中的ListView - ID为'@android:id/list'的布局文件 - 并且不会生成它自己的布局文件。 – 2012-02-01 18:30:47

+0

非常感谢!这工作完美! **:)** – 2012-02-02 14:46:25