3

I want my whole activity to scroll at once, but the ListView which is embedded in my ScrollView won't expand. I just see the first row, but I can scroll through the other rows, when scrolling the listView. What I need is for the listView to expand in height so every items it contains are displayed without having to scroll the listview, only the main scrollView...

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:orientation="vertical"
        android:layout_weight="1" >
        <LinearLayout
            android:id="@+id/header_Layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal" >

        ...

        </LinearLayout>
        <TextView
            android:id="@+id/comment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/gradient_background"
            android:text="@string/comments"
            android:textColor="#000000"
            android:textStyle="bold" >
        </TextView>

        <ListView
            android:id="@+id/commentsListView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="fill"
            android:divider="@drawable/gradient_divider"
            android:dividerHeight="1dp" />
    </LinearLayout>
</ScrollView>
user1026605
  • 1,633
  • 4
  • 22
  • 58
  • You can refer to this post http://stackoverflow.com/questions/3495890/how-can-i-put-a-listview-into-a-scrollview-without-it-collapsing – Emmanuel Sys Dec 11 '11 at 15:23

1 Answers1

4

One of the main purposes of a ListView is to enable recycling of cells while scrolling. If you want all the cells to exist, then you don't need a ListView. Just use a vertically oriented LinearLayout.

Brigham
  • 14,395
  • 3
  • 38
  • 48
  • you're totally right ! I don't really need a ListView, I can obtain the same result with a simple LinearLayout. I just need to handle the dividers by hand. – user1026605 Dec 11 '11 at 17:21