开发者

ListView ignoring wrap_content

开发者 https://www.devze.com 2023-01-27 03:35 出处:网络
I have a problem with the ListView in Android. When I set android:layout_height=\"wrap_content\", ListView stays just one or two rows long and I can\'t find a way to make him \"wrapped\".

I have a problem with the ListView in Android. When I set android:layout_height="wrap_content", ListView stays just one or two rows long and I can't find a way to make him "wrapped".

<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"
            andro开发者_Go百科id: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>

Is there any way to accomplish this? Thanks in advance!


You should never set the height of a ListView to wrap_content. Either set the height to fill_parent or do something like this:

<ListView
    android:layout_height="0dp"
    android:layout_weight="1"
    />

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


It appears you're trying to add a header to your listview. Listview has built-in support for headers (and footers). The method for setting a header is listview.addHeader(View view). You can customize the header as needed.


use ExpandableHeightGridView.java of gitHub ExpandableHeightGridView Try for scrollview

0

精彩评论

暂无评论...
验证码 换一张
取 消