Pablo
07/19/2024, 9:14 PMColumn(
modifier = modifier.weight(1f),
It gives me this error: Unresolved reference: weight
It gives me 4 import possibilities but none of them do workCaleb Cook
07/19/2024, 9:18 PMPablo
07/19/2024, 9:20 PMPablo
07/19/2024, 9:20 PMPablo
07/19/2024, 9:20 PMPablo
07/19/2024, 9:20 PMZach Klippenstein (he/him) [MOD]
07/19/2024, 9:35 PMZach Klippenstein (he/him) [MOD]
07/19/2024, 9:35 PMPablo
07/19/2024, 9:36 PMPablo
07/19/2024, 9:36 PMAlex Styl
07/19/2024, 9:47 PM@Composable
@Sampled
fun SimpleColumn() {
Column {
// The child with no weight will have the specified size.
Box(Modifier.size(40.dp, 80.dp).background(Color.Magenta))
// Has weight, the child will occupy half of the remaining height.
Box(Modifier.width(40.dp).weight(1f).background(Color.Yellow))
// Has weight and does not fill, the child will occupy at most half of the remaining height.
// Therefore it will occupy 80.dp (its preferred height) if the assigned height is larger.
Box(
Modifier.size(40.dp, 80.dp)
.weight(1f, fill = false)
.background(Color.Green)
)
}
}
You can find other examples @ https://www.composables.com/foundation-layout/columnPablo
07/19/2024, 9:54 PMPablo
07/19/2024, 9:54 PMAlex Styl
07/19/2024, 10:04 PMweight()
modifier comes with column/rowAlex Styl
07/19/2024, 10:06 PMPablo
07/19/2024, 10:13 PMromainguy
07/19/2024, 10:45 PMPablo
07/19/2024, 10:51 PMromainguy
07/19/2024, 10:54 PM@Composable
fun RowScope.MyComposable(modifier: Modifier = Modifier) {
Column(modifier = modifier.weight(1f), …) {
…
}
}
romainguy
07/19/2024, 10:54 PMRowScope
(or ColumnScope
) receiver, remove the weight(1f)
from inside MyComposable
and let the caller pass the weight modifierPablo
07/19/2024, 11:00 PM