How can I prevent `LazyVerticalGrid` width from ex...
# compose
p
How can I prevent
LazyVerticalGrid
width from expanding? I want it to take min amount of width.
Copy code
LazyVerticalGrid(
        columns = GridCells.Fixed(3),
        verticalArrangement = Arrangement.spacedBy(17.dp),
    ) {
        items(items = items, key = { it }) { item ->
            Box {
                Key(icon = item.icon, modifier = Modifier.align(Alignment.Center))
            }
        }
    }
I want it to behave like following. Is that possible?
z
How can it know what the “min amount of width” is if it’s lazy? By definition it doesn’t what all its children are
s
Which would bring us to the next question. Why do you need laziness for a grid like this? You most likely don't.
☝🏻 1
p
I don't need lazy, but I need "grid". Is there any other existing component already provided that I'm missing here?
s
No that is true, I am not aware of any such layouts out of the box. You could either try to go with rows + columns and make it work that way. You could also just write your own Layout {} composable which does the grid placement, it shouldn't be too complicated. I bet if you google for it someone else might've already done a "grid but not lazy" implementation too
1
t
Grid but not lazy is just Row and Columns indeed 😅
s
Yeah I understand how it's not always that simple, since your rows/columns could then start being crooked if you can't force something like a fixed number of items in each row plus
Modifier.weight(1f)
on each and stuff like that.
y
You can use this; it's pretty neat. https://github.com/touchlane/gridpad-android