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

Stylianos Gakis

03/04/2024, 6:23 PM
If I got a composable, not inside a ColumnScope or anything, is it possible to somehow make it take 80% of the width while also centering its content in that available space? Basically from left to right I want it to have 10% spacing, 80% content, 10% spacing. If I am inside a Column, I can very easily do
Copy code
Modifier
  .fillMaxWidth(0.8f)
  .wrapContentWidth(Alignment.Start)
  .align(Alignment.CenterHorizontally)
But outside of a Column I am not sure. I feel like there is a way to achieve this
Aha while typing this out, I tried
Copy code
.fillMaxWidth(1f)
.wrapContentWidth(Alignment.CenterHorizontally)
.fillMaxWidth(0.8f)
And I think this does what I want 👀
g

Garret Yoder

03/04/2024, 9:21 PM
You could also wrap the composable in a box
box parent fills width, child fills .8f width
s

Stylianos Gakis

03/04/2024, 11:07 PM
In this context that was not the most convenient option. It's a modifier that I was passing down to a child, so I had to do it in a modifier. Also why introduce another wrapper if I can do it in a modifier anyway? And this one looked to just work, I'll test more tomorrow.
2 Views