Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: how to make a listview fill its parent without scrolling?

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>
like image 323
user1026605 Avatar asked Jan 23 '26 10:01

user1026605


1 Answers

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.

like image 136
Brigham Avatar answered Jan 26 '26 01:01

Brigham



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!