我想在列表视图的底部有一个按钮。
如果我使用relativeLayout/FrameLayout,它会对齐,但listView会下降到非常底部。
(在底部按钮后面)
框架布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true">
<Button
android:id="@+id/btnButton"
android:text="Hello"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
</FrameLayout>
</FrameLayout>
相对布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="@+id/btnButton"
android:text="Hello"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
</RelativeLayout>
</RelativeLayout>
上面的两个代码只能像第一个图像一样工作。我想要的是第二张图片。
有人可以帮忙吗?
谢谢。
A FrameLayout
其目的是将事物叠加在一起。这不是你想要的。
In your RelativeLayout
例如你设置ListView
s 的高度和宽度MATCH_PARENT
这将使它占用与其父级相同的空间,从而占用页面上的所有空间(并覆盖按钮)。
尝试类似的方法:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"/>
</LinearLayout>
The layout_weight
规定如何使用额外的空间。这Button
不想拉伸超出其所需的空间,因此它的权重为 0。ListView
想要占据所有额外空间,因此它的权重为 1。
您可以使用以下方法完成类似的事情RelativeLayout
,但如果只是这两项那么我认为LinearLayout
更简单。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)