android - 如何在 Android 中定位 ListView?

标签 android android-layout android-listview

我想在我的 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/

相关文章:

java - Android:带有左侧状态行的 ListView

android - 在 AppCompat 主题中覆盖默认 ListView 突出显示的颜色

android - 从我的应用程序打开电子邮件应用程序

java - 如何使用代码设置 Activity 的背景?

android - 如何从 Android 中的视频文件中分离音频流比特率?

java - iText - Java Android - 将字段添加到现有 pdf

java - 删除 fragment 不起作用

android - 线性布局上的图像重叠

android - 当我使用自定义适配器时如何从 Android 中的 ListView 获取数据

android - 我如何在listview android中切换三个以上的图像