https://kotlinlang.org logo
Title
s

spierce7

12/04/2020, 9:25 PM
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.
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

Dominaezzz

12/04/2020, 9:33 PM
What if you leave out the
Modifier.fillParentMaxHeight()
?
s

spierce7

12/04/2020, 9:37 PM
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

Dominaezzz

12/04/2020, 9:44 PM
Perhaps a
ListItem
could do.
s

spierce7

12/05/2020, 8:37 PM
Found the solution. Modifier.align. Gives similar results to Gravity