8

My goal is to have a NestedScrollView with multiple child CardViews containing RecyclerViews.

My current xml looks something like this:

    <CardView>
        <RecyclerView/>
    </CardView>

    <CardView>
        <RecyclerView/>
    </CardView>
</NestedScrollView>

Everything appears to be working as expected if i set nestedScrollViewEnabled to false on the RecyclerViews. However, the rows in the recyclerviews are not being recycled. Calling layoutManager.findFirstVisibleItemPosition() always returns 0, and layoutManager.findLastVisibleItemPosition() always returns the last item position in the list.

Any suggestions?

user1377493
  • 143
  • 1
  • 8
  • "not being recycled" - didn't understand – Reaz Murshed May 02 '16 at 17:57
  • As if the list has a total of 30 rows, then 30 rows are inflated. It is supposed to inflate about the number of rows which is visible on the screen. In my case 6 rows should be inflated only, and "recycled" as I scroll; which is the case if I remove the nestedScrollView – user1377493 May 02 '16 at 18:01
  • any luck with this issue yet?? – hushed_voice Dec 03 '19 at 14:35
  • When a recycler view is inside another scrollable layout, **it will not recycle views by design** (this is most likely a limitation of the design, since the recyclerView is no longer in control of the scrolling, and the ScrollView or NestedScrollView doesn't talk to the RV to inform it of the scrolling/visibility situation. The RV then resorts to this behavior. I normally advice people to avoid using RVs inside ScrollViews unless they are very small RVs. – Martin Marconcini Jul 15 '21 at 10:50

1 Answers1

0

From what You have explained, it seems that all the views are being rendered off the screen, that's why you are getting last item position of recycler. Try setting

recyclerview.recycledViewPool.setMaxRecycledViews(int viewType, int max)

set max between 7 to 10 or more

I hope this works

QAMAR
  • 2,684
  • 22
  • 28