Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filling remaining space with Spacer on Jetpack Compose

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")
}

Edit

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.

like image 360
Eduardo Naveda Avatar asked Aug 31 '25 13:08

Eduardo Naveda


1 Answers

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") 
}
like image 152
Steffen Funke Avatar answered Sep 02 '25 07:09

Steffen Funke