Zhang Zihan
10/18/2024, 10:44 AMLazyVerticalGrid
be in the CenterEnd
of the cell?
I tried the following code, but it doesn't work, the label is always at the top of the cell
@Composable
fun LazyVerticalGrid2Columns(value: List<Pair<String, @Composable () -> Unit>>) {
LazyVerticalGrid(
columns = GridCells.Fixed(2),
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalArrangement = Arrangement.Center,
) {
value.forEach { (label, widget) ->
item { Box(Modifier.fillMaxSize(), contentAlignment = Alignment.CenterEnd) { Text(label) } }
item { Box(Modifier.fillMaxSize(), contentAlignment = Alignment.CenterStart) { widget() } }
}
}
}
Stylianos Gakis
10/18/2024, 11:28 AMZhang Zihan
10/18/2024, 11:41 AMStylianos Gakis
10/18/2024, 12:07 PMModifier.border(1.dp, Color.Red)
around each text composable, what are their bounds?
With that you may be able to tell if the items are centered properly but then some spacings in the font is what makes them look crooked.
Also what is widget()
versus just Text(label)
? Does widget do something special?Zhang Zihan
10/18/2024, 12:24 PMwidget()
is a Text()
, I expect it could be any Compose function, like Image
, Button
, Card
Stylianos Gakis
10/18/2024, 12:45 PMLazyColumn {
item {
FullHorizontalItem("label1", "abc")
}
}
fun FullHorizontalItem() {
Row {
Text(weight(1f))
Text(weight(1f))
}
}
so have each lazy item contain both the left and the right side, and align them inside one single composable instead.
That's what I'd try at least.Zhang Zihan
10/18/2024, 1:10 PMLazyVerticalGrid
to get better performance, but it seems a bit too limited at the moment 😢Stylianos Gakis
10/18/2024, 1:41 PMZach Klippenstein (he/him) [MOD]
10/18/2024, 4:21 PM