ListView not expanding inside NestedScrollView
Solution 1
For the CoordinatorLayout
to work properly you need the scrolling child to implement NestedScrollingChild. Such classes are NestedScrollView
and RecyclerView
.
To say it short - just use a RecyclerView
for your scrolling content and it'll work correctly :)
P.S. As a side note, I don't see a reason why you'd use a ListView
anymore. I know it's a habit and it's easier to setup (because you've done it many times), but using a RecyclerView
is the recommended way anyways.
Solution 2
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>
Solution 3
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
Solution 4
this is what worked for me.
set android:fillViewport="true"
on the NestedScrollView
add One Layout Element as Child to NestedScrollView
. In my case LinearLayout
and then
set android:nestedScrollingEnabled="true"
on ListView
Make ListView
a child of LinearLayout
Good to go
Solution 5
Just put android:fillViewport="true"
inside you NestedScrollView
Tag
Comments
-
Bincy Baby almost 2 years
I am using
CoordinatorLayout
in my activity page. In that there isListView
below the app bar. But its not working when I useListView
instead ofNestedScrollView
. And if I putListView
insideNestedScrollView
,ListView
is not expanding -
sha over 8 yearsI dont see a fastscroll and section adapter implementation for recycler view yet
-
Sagar Panwala over 8 yearsHow can I implement Expandable listview
-
Blodhgard over 8 yearsRecyclerView doesn't handle the CursorAdapter. This could be a good reason!
-
Irritator over 8 yearsYou could use Shywims custom CursorRecyclerView Adapter: gist.github.com/Shywim/127f207e7248fe48400b
-
Luis E. Fernandez over 8 yearsDidn't worked for me too. The ListView content isn't scrollable.
-
Alpha Huang about 8 yearsMay I know your API level?
-
piyush poriya about 8 yearsListview not scrolling
-
txedo about 8 yearsandroid:fillViewport="true" works like a charm. Also keep in mind that a recycler view may be more appropriate in most cases (e.g. the whole list or individual items updates dynamically at runtime).
-
Aziz about 8 yearsPlease explain how your answer solves the problem, it will help everyone understand your solution with more clarity and for future reference.
-
Shivam about 8 years@Aziz actually I was also facing same problem and it worked. on setting "fillViewport" true it stretch the content's height to the viewport's boundaries,
-
Waleed A. Elgalil almost 8 yearsWorked with me So Thanks , you are really saved my time. just Added the tag android:fillViewport="true"
-
Darwind over 7 yearsThis answer should definitely be upvoted and even set as the correct answer now. I ended up changing my implementation to a
RecyclerView
because I only read the answer that was accepted as the answer. Yes of course I could've read all the answers, but the first one worked for me - if was just a hassle to change the implementation ;-) -
Jürgen 'Kashban' Wahlmann over 7 yearsWorked for me +1. I have a ConstraintLayout within the NestedScrollView and it didn't scale up to full height without that flag.
-
james over 7 yearsTry enabling programmatically like "nestedScrollView.setNestedScrollingEnabled(true);"
-
sam over 7 yearsIt helped. I have spent two days searching for the solution.
-
Keno over 7 yearsWell it did expand the viewport, but it isn't scrollable for me.
-
Keno over 7 yearsThis one is only supported in API 21 and higher. Unfortunately I'm building for 16 minimum.
-
Ivan Milisavljevic about 7 yearsmore details on should or should we not replace ListView with Recycler view stackoverflow.com/questions/28392554/…
-
Dogcat about 7 yearsCalling ViewCompat.setNestedScrollingEnabled(listView, true) does the trick with a ListView.
-
liltof almost 7 yearsYou just saved me! And yes this should be the accepted answer
-
kreker over 6 years@Dogcat no, it's not. Docs "If this view does not implement nested scrolling this will have no effect."
-
kreker over 6 yearsNo, it's not working. Docs say "If this view does not implement nested scrolling this will have no effect."
-
Hrk over 6 yearsThe ViewCompat does nothing before Android Lolipop: stackoverflow.com/questions/32811121/…
-
zuko almost 6 yearsI was about to say the same thing until I read this. This solution is good for API 21+
-
Jacob Sánchez about 5 years"I don't see a reason why you'd use a ListView anymore" Can't you just answer the ... question?
-
JWL over 4 yearsOnly solution that's worked for me. And Using the LinearLayout helps in composing a composite ui nested inside the outer NestedScrollView. Thanks!