简体   繁体   中英

ListView in a fragment doesn't size correctly

I want to display a ListView while a button is pressed (actually several buttons and ListViews but I narrowed here to 1 for clarity purposes), and I want the ListView to display to take all the remaining space in the screen if needed.

Instead, I get a scrollable ListView which size is exactly the one of 1 item + 1 header, and a lot of empty space at the bottom.

This is my main Layout :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/editUserPlaces"
        style="@style/textView_bar"
        android:background="@drawable/button_text_dark_grey_bot_or_alone"
        android:drawableEnd="@drawable/chevron_grey_for_open"
        android:text="@string/edit_user_places" />

    <FrameLayout
        android:id="@+id/venue_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

When I press the button, the FameLayout is replaced by the Fragment containing my ListView :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_list_venue"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <android.support.v7.widget.SearchView
        android:id="@+id/editUserVenueFilter"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:paddingLeft="10dp" />

    <se.emilsjolander.stickylistheaders.StickyListHeadersListView
        android:id="@+id/listviewvenue"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

</LinearLayout>

Changing

android:layout_height="0dp"
android:layout_weight="1"

by

android:layout_height="match_parent"

doesn't help either.

I ran out of ideas...

Thanks if anybody can help!

Change

<FrameLayout
        android:id="@+id/venue_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

with

<FrameLayout
        android:id="@+id/venue_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

try it...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM