Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView not expanding inside NestedScrollView

I am using CoordinatorLayout in my activity page. In that there is ListView below the app bar. But its not working when I use ListView instead of NestedScrollView. And if I put ListView inside NestedScrollView, ListView is not expanding

like image 584
Bincy Baby Avatar asked Oct 01 '15 06:10

Bincy Baby


2 Answers

you can fix it when you add addtribute android:fillViewport="true" in android.support.v4.widget.NestedScrollView :) . This my code.

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:fillViewport="true"
    >
    <ListView
        android:id="@+id/list_myContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"
        >
    </ListView>

</android.support.v4.widget.NestedScrollView>
like image 81
Chung Nguyen Avatar answered Oct 23 '22 08:10

Chung Nguyen


on Lollipop onwards you can use

setNestedScrollingEnabled(true);

on your ListView/GridView/ScrollableView. From the documentation

Enable or disable nested scrolling for this view

if you need backwards compatibility with older version of the OS you'll have to use the RecyclerView. You can read more here

Edit. ViewCompat has the static method setNestedScrollingEnabled(View, boolean). Eg.

ViewCompat.setNestedScrollingEnabled(listView, true)

thanks to @Dogcat for pointing it out

like image 51
Blackbelt Avatar answered Oct 23 '22 08:10

Blackbelt