Hello all. Is it possible to create a LazyVertical...
# compose-android
s
Hello all. Is it possible to create a LazyVerticalGrid with like a Dynamic number of grid size? Whereby a particular row or grid has like two items and then the next just one item. I have a picture attached under this reply to describe what I mean
Something like this
Also maybe with some dynamic height too if possible
h
you can control the span
s
How can I do that please? The design requirements are not 100% clear, but no issue I will contact the designer on that, for now what I am thinking of maybe randomising it whereby some span size will be 1 or 2(randomly) and the images will adapt according to that.
I thought of this because the items in the list could be a lot
so I found a way. Just in case anyone faces this same issue and comes to this thread. We can dynamically set the spanSize for the gridItems using the
span { GridItemSpan() }
that the items and itemsIndexed provides for us. For my usecase, I wanted the items to be placed in a 2 by 1 span which gets looped just like in the image above, so I used the itemsIndexed with its span parameter like this.
Copy code
span = { index, _ ->
    val spanCount = if (index % 3 == 2) 2 else 1
    GridItemSpan(spanCount)
}
I think the code part is pretty self-explanatory but we want to place, starting from the first two items in the list in a single row(span2) and then next item alone(span1) in the next row