我想在我的 Activity 顶部放置一个 ListView
,在底部放置其他东西而不是 ListView
“吞噬”底部的小部件?我尝试了这个(“其他东西”是一个 RelativeLayout
,其中有一个按钮),但它不起作用。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" >
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_gravity="bottom" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Button" />
</RelativeLayout>
</LinearLayout>
我寻找了一些提示 here ,这非常有用,但没有说明任何关于 ListView
的内容。我可以毫无问题地将小部件放在 ListView
上方,但不能放在下方。
最佳答案
使用 RelativeLayout 作为根布局,然后使用 layout_above
定位 ListView 并使用 layout_alignParentBottom
定位 Button:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/button" >
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Button" />
</RelativeLayout>
关于android - 如何在 Android 中定位 ListView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14467485/