1

Is there any way to get a RecyclerView with different spanCount for every row depends on how many items can fit in a row ? Meaning when there is no more width to fit new item, it will break into a new row.

I've attached a photo so you can see what I need.

If can't be done with RecyclerView, can it be done with TableLayout ? or a listView ?

enter image description here

Gilad Eshkoli
  • 1,253
  • 11
  • 27

3 Answers3

1

You can do this with a Recycler View and a custom Layout Manager

This article might help http://wiresareobsolete.com/2014/09/building-a-recyclerview-layoutmanager-part-1/

(sorry I don't have code to share. ive never done this, but i think its possible to do accomplish it this way)

Shmuel
  • 3,916
  • 2
  • 27
  • 45
0

The solution is FlexLayoutManager:

https://github.com/google/flexbox-layout

All you need to do is to add it in Gradle (1.1.0 for project using AndroidX artifacts, 1.0.0 other way):

implementation("com.google.android:flexbox:1.1.0")

And create it like this:

recycler.layoutManager = FlexboxLayoutManager(context, FlexDirection.ROW)
Michał Powłoka
  • 1,424
  • 1
  • 13
  • 31
0

You can use ChipsLayoutManager also. https://github.com/BelooS/ChipsLayoutManager

implementation'com.beloo.widget:ChipsLayoutManager:0.3.7@aar'

allprojects {
repositories {
    jcenter()
}

}