How to center elements inside the first Column which is embedded inside a Row:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MaterialTheme {
Row {
Column(modifier = LayoutPadding(top = 16.dp)) {
Text(text = "Centered ", style = TextStyle(fontSize = 30.sp, fontWeight = FontWeight.Bold))
}
Column {
Text(text = "Line One ", style = TextStyle(fontSize = 30.sp, fontWeight = FontWeight.Bold))
Text(text = "Line Two ", style = TextStyle(fontSize = 30.sp, fontWeight = FontWeight.Bold))
}
}
}
}
}
}
In this example I hardcoded padding, but was not able to figure out how to center the elements out of the box. If there is no such an option, how can I get a height of the whole Row?
You can use the Modifier.align
in your Column
Row (){
Column( modifier = Modifier.align(Alignment.CenterVertically)){
Text(text = "Centered ", style = textStyle)
}
Column {
Text(text = "Line One ", style = textStyle)
Text(text = "Line Two ", style = textStyle)
}
}
or you can use the verticalAlignment = Alignment.CenterVertically
in the Row
element:
Row (verticalAlignment = Alignment.CenterVertically){
Column(){
Text(text = "Centered ", style = textStyle)
}
Column() {
Text(text = "Line One ", style = textStyle)
Text(text = "Line Two ", style = textStyle)
}
}
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