Gilad Eshkoli
Gilad Eshkoli

Reputation: 1263

RecyclerView with different spanCount for each row

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

Upvotes: 1

Views: 628

Answers (3)

Madhura Prasanna
Madhura Prasanna

Reputation: 189

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

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

allprojects {
repositories {
    jcenter()
}

}

Upvotes: 0

Michał Powłoka
Michał Powłoka

Reputation: 1511

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)

Upvotes: 0

Shmuel
Shmuel

Reputation: 3916

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)

Upvotes: 1

Related Questions