Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 980
Siraj Sumra Avatar asked Nov 27 '25 07:11

Siraj Sumra


1 Answers

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

like image 70
Jaymin Avatar answered Nov 29 '25 21:11

Jaymin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!