https://kotlinlang.org logo
#compose
Title
# compose
a

Alexjlockwood

03/07/2022, 7:52 PM
say i have a column like this:
Copy code
Column(Modifier.wrapContentHeight()) {
    Box(Modifier.fillMaxWidth().weight(1f).background(Color.Red)) { ... }
    Box(Modifier.fillMaxWidth().height(100.dp).background(Color.Blue)) { ... }
}
i was expecting the
Modifier.wrapContentHeight()
to compress the
weight(1f)
down such that both of the inner boxes would simply wrap their own content (since this was how it worked with vertical linear layouts). but i found that the
weight(1f)
still caused the
Column
to expand to fill its maximum height regardless. basically i’m wondering if there is a way for me to control whether the
weight(1f)
expands or not simply by passing a modifier to the parent `Column`… my current workaround is adding a
fillMaxHeight: Boolean
parameter to my composable function to decide whether or not the
weight(1f)
is applied but it felt kind of dirty
a

Adam Powell

03/07/2022, 8:21 PM
weight
has a second parameter 🙂
1
4 Views