Search code examples
javaandroidandroid-studioandroid-recyclerviewstaggered-gridview

Staggered Grid View (Both Directions) - different cells width - vertical scroll


I need to make panel of some sort with a Staggered Grid behavior such in the photo attached (cells width are not the same in each cell):

enter image description here

I tried normal GridView, I tried StaggeredGridLayoutManager with and without a recycler view, I've searched the internet for so long, and still hasn't found anything that gave me the suitable solution in java.

I also tried with the following answer: LayoutManager for RecyclerView Grid with different cell width and Android Grid view with different width of column (There are many more answers similar to this 2), but I need it to be "dynamic" and what I mean by that is that I need the cell width to be determine by it's content width and not just by it's index like in the answers attached.

Anyone knows a way to accomplish such a thing? or knows a library or a similar project with that feature?


Solution

  • It looks like https://github.com/google/flexbox-layout may help you.

    You can use FlexboxLayoutManager as adapter and play with properties, all the views will wrap automatically depending on their width.