Stylianos Gakis
03/08/2022, 12:37 PMLayout{}
I wanted to have all children have the exact same height. But I only get once chance to measure all of them and giving them constraints. Optimally I’d like to get a measurement of all of them, get the max height among them and have them all measure with the constraints to exactly match that height. This feels like one of the things that intrinsic layouts should be achieving, but I am not quite sure how to use intrinsics in my custom Layout {}
measurePolicy
. Any ideas of what I’m missing or an example I could look at?
Currently starting off by doing something like but I can’t quite find what I want to do instead:
Layout(
content = content
) { measurables, constraints ->
val width = (constraints.maxWidth / 2) - (horizontalSpacingInPx / 2) // I am placing 2 side by side
val height = measurables.maxOf { it.maxIntrinsicHeight(width) } // What would I do here instead
val placeables = measurables.map { measurable ->
val halfWidthAndIntrinsicMaxHeightConstraint = constraints.copy(
minHeight = height,
maxHeight = height,
maxWidth = width,
minWidth = width
)
measurable.measure(halfWidthAndIntrinsicMaxHeightConstraint)
}
Albert Chang
03/08/2022, 12:51 PMStylianos Gakis
03/08/2022, 1:12 PMcontent
with a simple Text()
and it worked, and I realized I was messing this up by doing adding a modifier on those children.
I was using this before.
.requiredHeightIn(min = 80.dp)
Replaced it with this and it now works
.defaultMinSize(minHeight = 80.dp)
That was interesting, I don’t know why I used the former, probably because I saw the name and it looked fitting and didn’t know about defaultMinSize before 😄Tobias Suchalla
03/08/2022, 2:06 PMAnalogue ofwhich allows to subcompose the actual content during the measuring stage for example to use the values calculated during the measurement as params for the composition of the children.Layout
Stylianos Gakis
03/08/2022, 2:17 PMAlbert Chang
03/08/2022, 3:28 PMSubcomposeLayout
here. It doesn't break the rule that a layout can only be measured once so you have to use intrinsics anyway.Zach Klippenstein (he/him) [MOD]
03/08/2022, 3:58 PMStylianos Gakis
03/08/2022, 4:00 PMZach Klippenstein (he/him) [MOD]
03/08/2022, 4:05 PMStylianos Gakis
03/08/2022, 4:06 PMZach Klippenstein (he/him) [MOD]
03/08/2022, 4:07 PMDoris Liu
03/08/2022, 6:44 PM