Hey everyone, is there a way to assign a weight su...
# compose
t
Hey everyone, is there a way to assign a weight sum to a Row, like there is with LinearLayouts? For example, I have this:
Copy code
Row {
    columns.forEach {
        Card(Modifier.weight(1f))
    }
}
In my case the number of columns is dynamic, and the max number of columns is 3 And I get a row looking like this, when I have 3 columns: (each card has weight 1) [ ] [ ] [ ] And when there is only 1 column, I get this: (each card has weight 1) [ ] I wanted to get this: (each card has weight 1, weight sum is 3) [ ]
a
You can use a
Spacer
with the weight remained.
Or you can use
Modifier.fillMaxWidth(fraction = 1 / 3f)
on the first card, and
Modifier.fillMaxWidth(fraction = 1 / 2f)
on the second, and so on.
t
Thanks, the second workaround will do nicely 🙂
v
I think there is also a fill parameter in weight which should do it
z
It would also be pretty easy to make a custom layout for this that could also do stuff like enforce that there are only three children.
t
@*zachklipp* Yeah that would probably be a good way to learn about creating custom layouts 🙂 i'm just starting with Compose, loving it though. But I think a weightSum should still exist