StaggeredGridLayoutManager
doesn\'t seem to allow customising a cell width or span multiple columns (except full span) for vertical orientation
Finally did it, it will help everyone who is trying to achieve any kind of patterns
I was looking for the same result but with one header and lazy loading footer. I tried @Kristyna answers of Nick Butcher Library too. But it has many issues like fast scrolling view disappear problem with the extra space or fixed cell height issue.
I found another library of Arasthel SpannedGridLayoutManager and tried to implement it. But it also has many issues like fixed height and footers extra space issue
Finally, after 5hr of digging Arasthel's SpannedGridLayoutManager, I fixed the issues and found my result.
My final edited forked library download from here SpannedGridLayoutManager.
In my case
val adapter = GridItemAdapter()//This is your adapter
val spannedGridLayoutManager = SpannedGridLayoutManager(orientation = VERTICAL, spans = 3)
spannedGridLayoutManager.itemOrderIsStable = true
recyclerview.layoutManager = spannedGridLayoutManager
For the first image result
spannedGridLayoutManager.spanSizeLookup = SpannedGridLayoutManager.SpanSizeLookup { position ->
when {
position == 0 -> {
/**
* 150f is now static
* should calculate programmatically in runtime
* for to manage header hight for different resolution devices
*/
SpanSize(3, 1, 150f)
}
position % 7 == 1 ->
SpanSize(2, 2)
else ->
SpanSize(1, 1)
}
}
recyclerview.adapter = adapter
And the second image result
spannedGridLayoutManager.spanSizeLookup = SpannedGridLayoutManager.SpanSizeLookup { position ->
when (position % 8) {
0, 5 ->
SpanSize(2, 2)
3, 7 ->
SpanSize(3, 2)
else ->
SpanSize(1, 1)
}
}
recyclerview.adapter = adapter
This spanSizeLookup logic may vary according to the requirement, for me I had set it randomly for testing purposes.