Maintain scroll position in nested RecyclerViews

I have ViewHolderone that contains another RecyclerView. This type ViewHolderis reused several times.

Since it ViewHolderis split between different items, the scroll position is RecyclerViewalso split between items. For example, you scroll to the end of the first element, the fifth RecyclerView element also scrolls to the very end, because the view is reused.

I am trying to solve this by matching 1 ViewHolderto 1 element.

I tried setting itemIdfor an element, call RecyclerView.ViewHolder # setIsRecyclable (false) and continue / set RecyclerView.getRecycledViewPool().setMaxRecycledViews()as indicated in this answer

After scrolling down and scrolling back ( ViewHoldergets recirculated), the scroll position of the internal RecyclerView reset to the first item.

+4
source share

Source: https://habr.com/ru/post/1660818/


All Articles