Is there a trick to centering things in compose? i...
# compose-desktop
s
Is there a trick to centering things in compose? i.e. in a Lazy Column, for each item if I have some text, and then a divider at the bottom, I’m finding it exceptionally verbose to center the text vertically, and have the divider at the bottom.
Copy code
LazyColumnFor(state.value.products) { productState ->
            Column {
                Column(verticalArrangement = Arrangement.Center, modifier = Modifier.height(50.dp)) {
                    Text(
                        productState.product.name,
                        modifier = Modifier.fillParentMaxHeight(),
                    )
                }
                Divider(thickness = 1.dp, modifier = Modifier.height(1.dp))
            }
        }
d
What if you leave out the
Modifier.fillParentMaxHeight()
?
s
right - that was a bug from playing around with things. That leaves me with a result that’s centered
A column in a column is just unexpectedly verbose. Is that just what I should expect?
and technically it’s still not centered because of the divider at the bottom of 1px. If I truly wanted it centered, I’d need to draw the divider on top
d
Perhaps a
ListItem
could do.
s
Found the solution. Modifier.align. Gives similar results to Gravity