How to make RecyclerView do recycling inside NestedScrollView?
Asked Answered
O

0

11

I tried to put several views, including RecyclerView, into a NestedScrollView. I used setNestedScrollingEnabled(false) and it looked nice for small data sets but started to be laggy for bigger ones.

After spending some time on logging the onCreateViewHolder() method I understood that the recycler view creates them all at once as the old ListView. I tried to find reasons of such behavior in RecyclerView docs, but I found it in ScrollView description:

You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.

I hoped that NestedScrollView would solve the issue but it appears that it hadn't.

Are there any ways, for example, using some custom LayoutManager to use RecyclerView with its optimizations of view recycling?

P.s. Of course, I know about method getItemViewType(int pos) and possibility to add custom headers and footers using this technique but it looks like an ugly workaround for me. And yes, I am using it at the moment, because it is better to have code that is harder to maintain than such big performance issue.

Ossification answered 14/3, 2017 at 9:58 Comment(6)
try it #31000581Minima
@Ossification Have you solved this issue? I'm also having the same problemSciomachy
Hey! Have u found a solution for this?Galimatias
@Ossification did you find any ways to recycle items under nested scrollviewHessler
My research has shown there is no easy way. at least in 2021. I'm working on a custom layout manager that may be able to resolve the issue, not sure if it will be good to be open sourced though.Ossification
So, if you need to do smth like this - your best solution is to use Concat Adapters, different item types or Coordinator / Motion layout to achieve the desired behavior.Ossification

© 2022 - 2024 — McMap. All rights reserved.