ListView忽略wrap_content

Cze*_*ogy 9 android android-layout

我在Android中的ListView有问题.当我设置时android:layout_height="wrap_content",ListView只保留一行或两行,我找不到让他"包裹"的方法.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:gravity="center">
            <TextView
                android:id="@+id/question" 
                android:layout_width="fill_parent"  
                android:layout_height="wrap_content" />
            <ListView android:id="@+id/ListView01"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </ScrollView>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

有没有办法实现这个目标?提前致谢!

bma*_*pin 30

您永远不应将ListView的高度设置为wrap_content.将高度设置为fill_parent或执行以下操作:

<ListView
    android:layout_height="0dp"
    android:layout_weight="1"
    />
Run Code Online (Sandbox Code Playgroud)

来源:http://www.youtube.com/watch?v = wDBM6wVEO70&t = 40m45s


Pat*_*ick 10

您似乎正在尝试向列表视图添加标题.Listview内置支持页眉(和页脚).设置标题的方法是listview.addHeader(View view).您可以根据需要自定义标头.