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) }
To center align content of Column along horizontal axis in Android Compose, set horizontalAlignment parameter with the value of Alignment. CenterHorizontally . Also, we may fill the maximum width by the Column using Modifier. fillMaxWidth().
If you want only to center horizontally just use: Column( modifier = Modifier. fillMaxWidth(), horizontalAlignment = Alignment.
A LazyColumn is a vertically scrolling list that only composes and lays out the currently visible items. It's similar to a Recyclerview in the classic Android View system.
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 ( ) { ... }
Use this
Column( horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With