https://kotlinlang.org logo
#compose
Title
# compose
r

Richard Steventon

08/11/2022, 3:00 PM
Does anyone know how to get the contents of a compose Row to be spaced by a minimum amount, but if the parent is larger, to then increase that spacing size? A combination of
Arrangement.spacedBy
and
Arrangement.SpaceBetween
?
c

curioustechizen

08/11/2022, 3:06 PM
I want to say you need to use a custom arrangement, but maybe I misunderstood your question. Can you describe with an example? Or visually?
r

Richard Steventon

08/11/2022, 3:08 PM
I have a column with a set of rows. Each row contains a mix of different width Composables. I want the width of all the rows to be the same (but not full screen). I also want a minimum width between the Composables in each row.
c

Casey Brooks

08/11/2022, 3:09 PM
My first thought is to use
Arrangement.spacedBy
, but add a
Spacer(Modifier.weight(1f))
between items. If theres enough space, those spacers should push the individual items out, but if the row isn’t wide enough the spacer will collapse to 0 width. Definitely not the cleanest solution and I haven’t actually tried it, but I think it should work.
r

Richard Steventon

08/11/2022, 3:10 PM
Yeah, that is what I thought would be an option too …. or else add padding to the left/right (but not to the left of first item or right of last item) and then a spacer between with weight. But I was hoping there was a better/easier way.
c

Casey Brooks

08/11/2022, 3:10 PM
But yeah, Kiran’s idea might be better, to just write a custom Arrangement for this, the source for the built-in ones looks like they’re pretty trivial to implement
r

Richard Steventon

08/11/2022, 3:12 PM
Even writing a custom layout would work, but would need to go through multiple passes as it figures out the max width, so I would need to check if the width constraint was unbound and if so, set the spacing, but if not, then divide up the width. I was hoping to get access to the parent width in the Row’s scope somehow without saving it and forcing multiple layouts.
Custom Layout code worked great.
8 Views