如何在Android中定位ListView?

pet*_*ohn 1 android android-layout android-listview

我想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>
Run Code Online (Sandbox Code Playgroud)

在这里寻找了一些提示,这非常有用,但没有提及ListViews.我可以将小部件置于上面ListView而不是问题,但不能在下面.

Sam*_*Sam 5

使用RelativeLayout作为根布局,然后使用List layout_above和Button 定位ListView layout_alignParentBottom:

<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>
Run Code Online (Sandbox Code Playgroud)