I'm creating a layout with Jetpack Compose and there is a column. I would like center items inside this column:
Column(modifier = ExpandedWidth) {
Text(text = item.title)
Text(text = item.description)
}
With 1.0.0
(tested with 1.0.0-beta08
) you can use these parameters:
horizontalAlignment
= the horizontal gravity of the layout's children.verticalArrangement
= the vertical arrangement of the layout's childrenSomething like:
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = "First item",
modifier = Modifier.padding(16.dp)
)
Text(
text = "Second item",
modifier = Modifier.padding(16.dp)
)
Text(
text = "Third item",
modifier = Modifier.padding(16.dp)
)
}
If you want only to center horizontally just use:
Column(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally
) {
Column ( ) { ... }