Mickael Bergeron Néron Mickael Bergeron Néron - 5 months ago 19
Android Question

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>



Answer

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.

Comments