-1

i have a context-menu with items in a ListView, all contained within a BottomSheet from the ASL/Design lib. The activity's root view is a CoordinatorLayout as specified by BottomSheetBehavior.

The problem I'm facing is that the ListView (R.id.problematic_list below) only renders the first list-item if the list-view-container's height is either wrap_content or even match_parent (R.id.list_container below). If this list container has a generous height set (eg: 400dp) then the full list renders as expected; along with extra space (since height is over-specified). The ListView is dynamically populated so I can't set a static height in the layout-xml file.

Is there a simple layout, attribute or programmatic workaround for allowing the ListView to both populate and render without over-allocating vertical space?

My initial configuration is as described here

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:fitsSystemWindows="true">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/primaryBlue"
        android:orientation="vertical"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:fitsSystemWindows="true">

        <android.support.v7.widget.Toolbar android:id="@+id/toolbar"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"_elevation" />

        <!-- main activity content -->
        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/toolbar"
            />
    </RelativeLayout>

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="true"
        android:layout_gravity="bottom"
        app:behavior_hideable="true"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

        <!-- layout_height= 300dp / wrap_content -->
        <LinearLayout
            android:id="@+id/list_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ListView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/problematic_list"
                />
            </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
xst
  • 2,536
  • 5
  • 29
  • 41
  • 1
    Any reason why you've put ListView inside linear layout inside scroll view? AFAIK ListViews are scrollable by default. – CoderP May 24 '18 at 18:30

1 Answers1

0

the NestedScrollView has its own set of height requirements in order to render fully. I removed it from the hierarchy and the list renders in all available space.

thanks @CoderP for the hint

xst
  • 2,536
  • 5
  • 29
  • 41