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:
But when I used StaggeredGrid, It is providing result as below:
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.