Why is my `Switch` outside of the `Row` even thoug...
# compose
f
Why is my
Switch
outside of the
Row
even though the code is inside the block?
a
Compose UI doesn't clip children by default. Add a clip modifier to the row and you'll see something a bit closer to what you might have expected.
It looks like your column containing the text is consuming all of the available width in the row before the spacer and switch have an opportunity to measure. Give the column a weight modifier and it will measure with the space remaining after the switch and spacer instead.
f
As far as I remember, adding a weight only to the last Composable should make it take up exactly as much space as it needs and the rest should be taken up by the elements before it. I've done that before. If I set a weight on the Column, I would need to know its exact width beforehand (which I can't)
That's what the
weight(1f)
on the Switch is for
a
No. The parent measures all children without a weight first and allocate the rest space according to the weight value, which means children without a weight will take up exactly as much space as they need.
☝️ 1
👍 1
f
@Albert Chang But this is what I was just saying
That's why I have the weight only on the last composable
Or how do I get the Switch to take up only the space it needs, and the rest for the Column?
k
Set the weight on the column
☝️ 1
f
Thank you, it's working. I guess I remembered that wrong.
m
@Florian Walther (live streaming) you are a bit stubborn xD This is the same as xml views i guess. You typically do not set the weigh on the things that you don’t want to get overlapped. So you just say: place me the switch, after that use the remaining space for the text