android无法在listview下放置linearlayout

Wil*_*aan 2 android android-layout

我想在listview下面放一个linearlayout,如果我把它放在listview上面我得到一个异常并且活动突然停止工作,当我把它放在listview下它没有出现时,我做错了什么?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >



    <ListView
        android:id="@+id/lvRestaurants"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </ListView>

        <LinearLayout
        android:id="@+id/llButtons"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/bDone"
            android:layout_width="153dp"
            android:layout_height="match_parent"
            android:text="Done" />

        <Button
            android:id="@+id/bCancel"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Cancel" />
    </LinearLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

tbr*_*lle 10

添加android:layout_weight=1到ListView.

其他布局没有出现的原因是因为listview占据了父布局中的所有位置(android:layout_height="fill_parent")

  • 使用android:layout_height ="0dp"和android:layout_weight = 1 for ListView. (6认同)