. Have some problems with constraints, more in thread 🧵
Stylianos Gakis
11/12/2021, 9:37 AM
Given my code that looks approx like this:
Copy code
Layout(
modifier = Modifier.size(40.dp),
content = {
Image(
painterResource(R.drawable.ic_something_with_24dp_size),
contentDescription = null,
modifier = Modifier.size(24.dp)
)
Box(modifier = Modifier.size(12.dp)) {}
},
) { measurables, constraints ->
val image = measurables[0].measure(constraints)
val circle = measurables[1].measure(constraints)
// etc.
}
What should I do to mage image and circle measure with 24 and 12 dp respectively?
Now it gives them both 40.dp size just because the constraints allow it, but I have explicitly given them 24 and 12dp instead.
Stylianos Gakis
11/12/2021, 9:39 AM
I just rubber ducked myself 😅
Setting the constraints as
Copy code
val image = measurables[0].measure(constraints.copy(minWidth = 0, minHeight = 0))
val circle = measurables[1].measure(constraints.copy(minWidth = 0, minHeight = 0))
Fixes the problem, as before the constraints passed down were min AND max 110 (aka 40.dp).
Very interesting that it was like that, it’s probably because the