Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: ListView hiding layout below when too many items

I have this FileBrowser layout. When the linked view opens, I fill the ListView programmatically. The problem is: When there is too much items in the listview, that is, when there is enough items for a scroll bar to appear, the LinearLayout below containing the two buttons disappears.

Not to much items. The LinearLayout containing the two buttons is there as it should: enter image description here

Too much items. I scrolled to the bottom and the LinearLayout containing the two buttons isn't there: enter image description here

My layout:

<LinearLayout
    android:id="@+id/baseContainer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:orientation="vertical">

    <TextView
        android:id="@+id/txtCurrentPath"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="@dimen/textSizeL"
        android:layout_gravity="center"
        android:text="/current/path/"/>

    <ListView
        android:id="@+id/filesListView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    </ListView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom|center_horizontal"
        android:orientation="horizontal">

        <Button
            android:id="@+id/cancelBtn"
            style="@style/RexforetTheme.Button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/icon_retour"
            android:text="@string/btn_cancel" />

        <Button
            android:id="@+id/selectBtn"
            style="@style/RexforetTheme.Button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/icon_check"
            android:text="@string/btn_select" />
    </LinearLayout>
</LinearLayout>

like image 372
Mickael Bergeron Néron Avatar asked Feb 10 '26 21:02

Mickael Bergeron Néron


1 Answers

Change your ListView xml to the following

<ListView
    android:id="@+id/filesListView"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:orientation="vertical"
    android:layout_weight="1">
</ListView>

The change of android:layout_height to 0dp and the addition of android:layout_weight="1" will allow the ListView to grow to use the rest of the available space in your layout.

This means that your two buttons will always be visible, and positioned at the bottom of the screen.

like image 160
Andrew Brooke Avatar answered Feb 15 '26 17:02

Andrew Brooke



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!