ListView not expanding inside NestedScrollView

47,362

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

Share:
47,362
Bincy Baby
Author by

Bincy Baby

:)

Updated on July 09, 2022

Comments

  • Bincy Baby
    Bincy Baby almost 2 years

    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

  • sha
    sha over 8 years
    I dont see a fastscroll and section adapter implementation for recycler view yet
  • Sagar Panwala
    Sagar Panwala over 8 years
    How can I implement Expandable listview
  • Blodhgard
    Blodhgard over 8 years
    RecyclerView doesn't handle the CursorAdapter. This could be a good reason!
  • Irritator
    Irritator over 8 years
    You could use Shywims custom CursorRecyclerView Adapter: gist.github.com/Shywim/127f207e7248fe48400b
  • Luis E. Fernandez
    Luis E. Fernandez over 8 years
    Didn't worked for me too. The ListView content isn't scrollable.
  • Alpha Huang
    Alpha Huang about 8 years
    May I know your API level?
  • piyush poriya
    piyush poriya about 8 years
    Listview not scrolling
  • txedo
    txedo about 8 years
    android: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
    Aziz about 8 years
    Please explain how your answer solves the problem, it will help everyone understand your solution with more clarity and for future reference.
  • Shivam
    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
    Waleed A. Elgalil almost 8 years
    Worked with me So Thanks , you are really saved my time. just Added the tag android:fillViewport="true"
  • Darwind
    Darwind over 7 years
    This 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
    Jürgen 'Kashban' Wahlmann over 7 years
    Worked for me +1. I have a ConstraintLayout within the NestedScrollView and it didn't scale up to full height without that flag.
  • james
    james over 7 years
    Try enabling programmatically like "nestedScrollView.setNestedScrollingEnabled(true);"
  • sam
    sam over 7 years
    It helped. I have spent two days searching for the solution.
  • Keno
    Keno over 7 years
    Well it did expand the viewport, but it isn't scrollable for me.
  • Keno
    Keno over 7 years
    This one is only supported in API 21 and higher. Unfortunately I'm building for 16 minimum.
  • Ivan Milisavljevic
    Ivan Milisavljevic about 7 years
    more details on should or should we not replace ListView with Recycler view stackoverflow.com/questions/28392554/…
  • Dogcat
    Dogcat about 7 years
    Calling ViewCompat.setNestedScrollingEnabled(listView, true) does the trick with a ListView.
  • liltof
    liltof almost 7 years
    You just saved me! And yes this should be the accepted answer
  • kreker
    kreker over 6 years
    @Dogcat no, it's not. Docs "If this view does not implement nested scrolling this will have no effect."
  • kreker
    kreker over 6 years
    No, it's not working. Docs say "If this view does not implement nested scrolling this will have no effect."
  • Hrk
    Hrk over 6 years
    The ViewCompat does nothing before Android Lolipop: stackoverflow.com/questions/32811121/…
  • zuko
    zuko almost 6 years
    I was about to say the same thing until I read this. This solution is good for API 21+
  • Jacob Sánchez
    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
    JWL over 4 years
    Only solution that's worked for me. And Using the LinearLayout helps in composing a composite ui nested inside the outer NestedScrollView. Thanks!