Sync Scrolling of Multiple Recyclerviews

Scrolling a page (fragment) with two RecyclerViews: State of the art & how about recycling?

This is precisely the use case for ConcatAdapter as per the Concatenate adapters sequentially with ConcatAdapter blog post:

ConcatAdapter is a new class available in recyclerview:1.2.0-alpha02 which enables you to sequentially combine multiple adapters to be displayed in a single RecyclerView. This enables you to better encapsulate your adapters rather than having to combine many data sources into a single adapter, keeping them focused and re-usable.

This allows you to write your layout as a single RecyclerView that correctly recycles views while keeping each individual adapter (and their loading of data) separate.

In your case, you should consider actually having 4 adapters - two simple ones for your titles (or two instances of the same TitleAdapter you could write), plus one for each of your previous adapters.

Then you'd construct your ConcatAdapter by passing all 4 adapters in to make one scrollable RecyclerView:

val firstTitleAdapter = TitleAdapter("first title")
val firstListAdapter: FirstListAdapter = …

val secondTitleAdapter = TitleAdapter("second title")
val secondListAdapter: SecondListAdapter = …

val concatAdapter = ConcatAdapter(firstTitleAdapter, firstListAdapter,
secondTitleAdapter, secondListAdapter)
recyclerView.adapter = concatAdapter

Sync al horizontal RecyclerView inside vertical list view

Make an instance of RecyclerView.OnScrollListener. This instance will be common to all your horizontal recycler views. When onScrolled( ) gets called, scroll all the views except the one on which this got called.



Related Topics



Leave a reply



Submit