https://kotlinlang.org logo
j

julioromano

03/04/2021, 10:30 PM
Copy code
Box {
  One()
  Two()
}
I have 2 composables inside a
Box()
. I’d like the Box to set its size to the size of
One()
and I’d also like that
Two()
adapts its size to the size of
One()
. Is this possible?
p

Piotr Prus

03/04/2021, 10:33 PM
Could you give us a graphic example?
j

julioromano

03/04/2021, 10:35 PM
Not really but I can explain with different words:
Two()
is the actual Box content (a bunch of Text composables neatly arranged in a few Rows and Columns).
One()
is the background image which should fill the the size occupied by
Two()
. Right now if I set `One()`’s modifier to
fillMaxSize()
it will expand and take up the whole screen, but I’d just like for it to expand to the same size as
Two()
.
d

Dominaezzz

03/04/2021, 10:54 PM
I think there's a wrapcontent modifier.
j

julioromano

03/04/2021, 11:20 PM
I’ve tried it but it doesn’t make things any better
d

Dominaezzz

03/04/2021, 11:22 PM
Why not use the background modifier?
🙌 1
j

julioromano

03/04/2021, 11:23 PM
Yupp! Just randomly tried that too and it works!
p

pavi2410

03/05/2021, 3:44 AM
In order to do that, I would have used ConstrainLayout
🙌 1
a

Archie

03/05/2021, 3:58 AM
you can possibly work around this by either: 1. Creating your own Composable:
Layout(...)
2. or
Copy code
var oneSize by remember { mutableStateOf(IntSize(0, 0)) }
val dpWidth = with(density) { dropDownSize.width.toDp() }
val dpHeight = with(density) { dropDownSize.height.toDp() }

Box{ 
   One(modifier = Modifier.onSizeChanged { oneSize = it })
   Two(modifier = Modifier.size(width = dpWidth, height = dpHeight)
}