1

Currently, I'm using a RecyclerView to display a set of views with different view types, where a group of consecutive items belongs together: a header, a variable set of content items, and a separator/footer. Current situation Now I also want my UI to look good on bigger devices, aka use multiple panes, so I switched to a StaggeredGridLayoutManager. The problem here is that it spreads views evenly between all spans, means one group gets spread over multiple columns. Situation with staggered LayoutManager Thus, I would like to specify that the layout manager puts a consecutive set of views into the same span, and only then put the next group in the next one. What I want Is this somehow possible with the LayoutManager I use? Can I modify it to work like that without just duplicating and editing it? Support lib devs: are there any plans to introduce such behaviour?

Please tell me whether I should provide any other information, and when something isn't clear enough.

Maxr1998
  • 1,179
  • 14
  • 22

1 Answers1

1

You can achieve your desired layout with the Support Library's StaggeredGridLayoutManager; you need to make each 'group' of items (e.g. header1 + 1-3 + footer) a single view returned by your adapter. This view could itself be a RecyclerView.

That is you'll have one outer RecyclerView with a StaggeredGridLayoutManager and multiple inner RecyclerViews with LinearLayoutManagers. You can likely share a single RecycledViewPool between the inner RVs. You'll have to do some gymnastics to create appropriate adapters for the inner RVs but this is likely simpler than writing your own LayoutManager!!

crafty
  • 2,730
  • 1
  • 21
  • 10
  • I used your suggestion and it worked very well, though I still have to work out some issues with my `CoordinatorLayout`, as it doesn't get the swipe feedback when you swipe on the child `RecyclerView`s. Also, I didn't know there was the option to share the view pool, very interesting! – Maxr1998 Apr 05 '17 at 21:04
  • EDIT: I realized I can just use `setNestedScrollingEnabled(false)`. Nice! – Maxr1998 Apr 05 '17 at 21:10