7

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 1

15

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

3
  • 5
    I 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.
    – Eaweb
    Mar 29, 2021 at 11:29
  • 1
    See 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/…
    – aldok
    Jun 8, 2022 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.