3

I need to be able to make a bi-directional RecyclerView. Basically, it would scroll vertically, but each row would be a horizontal list of tiles that could scroll. The initial scroll position would be at the top and left. The user could scroll down, and scroll to the right with each row.

Any ideas on how to do this? (e.g. with a custom LayoutManager or touch event interception).

afollestad
  • 2,929
  • 5
  • 30
  • 44
  • Try nested recycler views. Check this link http://stackoverflow.com/questions/26649406/nested-recycler-view-height-doesnt-wrap-its-content – random Jun 25 '15 at 05:06
  • https://www.youtube.com/watch?v=-C5I1DAviJ8 at some point in the presentation he speaks about what you want(or at least I think so) – user Jun 25 '15 at 05:11
  • `Basically, it would scroll vertically, but each row would be a horizontal list of tiles that could scroll.` **conflicts with** `scrollable views should not go in scrollable views` (which is **true**): That said, you could put a GridView in your RecyclerView's rows. – Phantômaxx Jun 25 '15 at 05:13
  • @DerGolem I know. There's ways to do it. Google engineers acknowledged that it's possible at some point for ListViews, but RecyclerViews are not ScrollViews and they do not measure themselves the same way as a ListView. – afollestad Jun 25 '15 at 05:14
  • How would you `scroll horizontally` without a scrollable View? Which is **inside** your `vertically scrollable` View. If you want both directions of scrolls... No one can save you. You **must** use a Scrollable in a Scrollable (which is **terrible**). – Phantômaxx Jun 25 '15 at 05:16
  • If you understand the code you linked, you'll see that that is a Scrollable in a Scrollable. There's no way to get out of it. It's really a `conditio sine qua non`. – Phantômaxx Jun 25 '15 at 05:21
  • @DerGolem an example of how they work differently: if you put a RecyclerView in a dialog, the dialog will fill the max height of a dialog regardless of content. ListViews do not. That's why material-dialogs (one of my libraries) uses ListViews rather than RecyclerViews. https://github.com/afollestad/material-dialogs. RecyclerViews measure differently via their layout managers. – afollestad Jun 25 '15 at 05:23
  • A ReciclerView is **obviously** not a ScrollView (**and who talked about ScrollViews?**). I am talking about **Scrollables** (which are **all those Views which can scroll**). – Phantômaxx Jun 25 '15 at 05:24
  • Then you're aware that you **can't have a scroll** (either horizontal or vertical) **without a Scrollable**. – Phantômaxx Jun 25 '15 at 05:26
  • @DerGolem yep. That's not the issue here. While Google advises people to not nest ScrollViews in ScrollViews, it's possible to do so with touch event interception. I'm looking for a solution with `RecyclerViews` and `LayoutManagers`. – afollestad Jun 25 '15 at 05:27

1 Answers1

1

I was able to solve the issue using a custom view implementation.

At the root, I have a custom ScrollView; when onMeasure is called, the ScrollView tells its children how tall they should. In this case, they are half the height of the ScrollView. The width matches the height so they display as square tiles.

Each of the ScrollView children are RecyclerView's with a horizontal LinearLayoutManager. Since the ScrollView tells each child how tall to be, there's no issues with measurement and they actually scroll very well in both directions (vertically and horizontally).

sample of solution

afollestad
  • 2,929
  • 5
  • 30
  • 44