Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView ignoring wrap_content

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"
            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>

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

like image 451
Czechnology Avatar asked Nov 29 '10 01:11

Czechnology


2 Answers

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.

like image 63
Patrick Avatar answered Oct 07 '22 00:10

Patrick


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

like image 39
bmaupin Avatar answered Oct 07 '22 00:10

bmaupin