Build a custom layout in Jetpack Compose
understanding Compose's measure/place model.
use the Layout composable with a MeasurePolicy, measure each child once with constraints, then place children and report your size.
WHAT THIS TESTS The interviewer wants to confirm you understand Compose's single-pass measurement model and can drop below the built-in containers to position children arbitrarily, rather than only composing existing layouts.
A GOOD ANSWER COVERS The Layout composable is the primitive behind Row, Column, and Box; you give it your content and a MeasurePolicy. When Compose lays out, it calls your MeasurePolicy's MeasureScope.measure function, handing you a list of Measurables (the children) and the Constraints from the parent. For each child you call measure(constraints), which returns a Placeable carrying the child's chosen width and height. A central rule is that each child may be measured exactly once; Compose enforces this to keep layout linear-time and avoid the quadratic re-measure passes of older view systems. After measuring, you decide your own size, which must satisfy the incoming constraints, and call layout(width, height). Inside that block you position every child by calling placeable.placeRelative(x, y) or place(x, y), choosing coordinates from your custom logic.
COMMON WRONG ANSWERS Measuring a child twice, which throws because Compose disallows multiple measurement of the same node. Ignoring the incoming Constraints and returning an arbitrary size. Confusing measure (sizing) with place (positioning) or forgetting that placement happens inside the layout block. Reaching for a nested combination of standard layouts when a single custom Layout is cleaner.
LIKELY FOLLOW-UPS How do intrinsic measurements work and when are they needed? How does the Modifier.layout variant differ from the Layout composable? How do you propagate or relax constraints to children? How does this compare to a custom ViewGroup's onMeasure and onLayout?
ONE CONCRETE EXAMPLE To build a simple vertical stack with custom spacing, your MeasurePolicy measures each child once with the parent constraints, sums their heights plus gaps to compute the total height and takes the max child width, calls layout with those dimensions, then iterates placing each Placeable at x equals zero and an increasing y offset. The result behaves like a lightweight Column you fully control.
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.