Issue
I’m creating a layout with Jetpack Compose and there is a column. I would like center one composable and the other to align to the bottom.
Here is an image of my target screen
here
I spent day working it out, SpaceAround
and SpaceBetween
didn’t help.
I would appreciate any help.
Solution
Use a Column with weight(1f)
and verticalArrangement = Arrangement.Center
to wrap the first item. Here’s the code
@Composable
fun Demo() {
Column(modifier = Modifier.fillMaxSize()) {
Column(
modifier = Modifier
.fillMaxWidth()
.weight(1f)
.background(color = Color.Transparent),
verticalArrangement = Arrangement.Center,
) {
Box(
modifier = Modifier
.fillMaxWidth()
.height(100.dp)
.padding(15.dp)
.background(color = Color.Green)
)
}
Box(
modifier = Modifier
.fillMaxWidth()
.height(60.dp)
.background(color = Color.Yellow)
)
}
}
@Composable
@Preview
fun DemoPreview() {
Demo()
}
Answered By – WS Ayan
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0