Is there a way to achieve "fill the rest of the space" in Compose without the extra Box
element wrapping the Spacer
? Spacer
has no weight modifier, unfortunately.
Column(
modifier = Modifier.height(120.dp).fillMaxWidth()
) {
Text(text = "A")
Box(modifier = Modifier.weight(1f)) {
Spacer(Modifier.fillMaxHeight())
}
Text(text = "B")
}
The extra box is not necessary at all. I was just misusing the modifier system. As a side note, the selected answer is probably another good way of achieving this.
As far as I can see, Column.arrangement
applies to all children evenly.
In case you just want to fill the remaining space to the max, a Spacer
with weight(1.0f)
modifier is probably what you want:
Column(
modifier = Modifier
.fillMaxWidth()
) {
Text("Text A") // top aligned
Spacer(modifier = Modifier.weight(1.0f)) // fill height with spacer
Text("Text B") // those two Texts are bottom aligned
Text("Text C")
}
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