Siraj Sumra
Siraj Sumra

Reputation: 954

Display tag like structure in Staggered Recyclerview

I am working on a tag structure currently and to display that I have used Staggeredgrid layout manager of Recyclerview to get the required result as below image:

enter image description here

But when I used StaggeredGrid, It is providing result as below:

enter image description here

My code to display adapter in Recyclerview is as given below:

val staggeredGridLayoutManager = StaggeredGridLayoutManager(2, LinearLayoutManager.VERTICAL)
rvTags.layoutManager = staggeredGridLayoutManager
rvTags.adapter = AllergyAdapter(tags)

On increasing the span count to 3, all the items are contracting. I want that if "Peanut butter" is big enough then only 1 item should come in 1 row and if "neem, garlic and soy" can fit in 1 row, then it should fit.

Basically, I need a way to dynamic span count according to the content size.

Any help will be appreciated.

The suggested answer is not working because it is counting span count for whole of Recyclerview and Not particular row wise.

Upvotes: 3

Views: 5303

Answers (3)

harishanth raveendren
harishanth raveendren

Reputation: 604

I came across such a requirement and ideally, a Flexbox should be a good option to try.

Upvotes: 1

kamran rahmatullah
kamran rahmatullah

Reputation: 35

layoutManager=new StaggeredGridLayoutManager(4, LinearLayoutManager.HORIZONTAL);

Upvotes: -3

Jaymin
Jaymin

Reputation: 2912

Either you can go with the dynamic spinning or what you can do is get the help of libraries.

Please check URL for tags libraries.

Tags Views

Here is a most suitable view: ChipView

With custom layouts : ChipView

And for dynamic column binding, you can use AsymmetricGridView.

URL : AsymmetricGridView

Upvotes: 1

Related Questions