Updated to Jetpack Compose a-08 today and have a problem. In previous builds I used weight modifier, but now i can't find it. What happened or what is the alternative? In changelogs I founded no information about it.
1 Answer
You can still find it there, but the weight modifier is a extension function inside RowScope
and inside ColumnScope
, which means you can only use it inside a Column
or a Row
.
Reference to RowScope: https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/RowScope#weight
Reference to ColumnScope: https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/ColumnScope#weight
-
5I ran into a similar issue while following the jetpack compose codelab today. To say the answer in another way, I am unable to use Modifier.weight() on a Column that's not a child of another column/row. Moving the column inside another column fixed it.– EawebMar 29, 2021 at 11:29
-
1See this answer for a better solution: stackoverflow.com/a/66599124/310783 Oct 16, 2021 at 21:37
-
I ran into similar problem. Another answer to use
weight
in a custom view stackoverflow.com/questions/71664252/…– aldokJun 8, 2022 at 14:13