java - 布局 Inflate 中的alignParentBottom

标签 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);

问题是,由于列表没有那么大,占据了整个屏幕(至少我认为这就是原因),因此按钮停留在列表的末尾,而不是粘在底部,因为 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/

相关文章:

android - 使父布局背景变暗/模糊

java - 安卓工作室 3.1.4 : missing classes and uncorrect Blueprint displaying

android - 使用 xml 布局在旋转之间保留数据

ruby-on-rails - Rails 3,如何添加一个不使用与应用程序其余部分相同布局的 View ?

android - setColorFilter 在 android 5 的 onTabSelected 事件中不起作用

java - 更改自定义 ProgressBar 的大小

java - JSplitPane 忽略对齐

java - 同时监听服务中的多个流

java - 字符串池和 String[]

java - 通过与旧值进行比较来拦截 DB 中的字段是否已使用 JAVA 更改