Search code examples
androidandroid-recyclerviewandroid-nestedscrollview

RecyclewView inside NestedScrollView cause UI freeze


I'm having a number of problems using a RecyclerView inside a NestedScrollView. I have a complete freeze of the UI when I have to do the set adapter. I've seen in other posts that it's a known issue but the solution seems to be to switch layouts. But the real problem, what is it?

Why am I using this configuration?

In my case I have to put an item at the bottom of the screen which: if the RecyclerView has few items it stays at the bottom and if I have more items than the screen can contain it is put at the bottom of the list. So with this configuration everything works except for the complete freeze of the UI. How can I fix?


Solution

  • Yes, using a RecyclerView inside a NestedScrollView can cause performance issues and freezes, especially when the RecyclerView has a large number of items. This is because the NestedScrollView is designed to handle scrolling of multiple views, and when it contains a RecyclerView, it has to handle both its own scrolling and the scrolling of the RecyclerView.

    To avoid this issue, it is recommended to use a different layout that is designed to handle a large number of items and scrolling, such as a RecyclerView with a LinearLayoutManager or GridLayoutManager.