Build a custom layout in Jetpack Compose
WHAT IT TESTS: understanding Compose's measure/place model. OUTLINE: use the Layout composable with a MeasurePolicy, measure each child once with constraints, then place children and report your size.
WHAT IT TESTS: whether you understand how Compose lays out children under the hood. ANSWER OUTLINE: the Layout composable lets you define arbitrary placement; you pass measurables and a MeasurePolicy. In measurePolicy you measure each child exactly once by calling measure(constraints), which returns a Placeable with its dimensions; you then compute your own size within the incoming constraints and, inside layout(width, height), call placeRelative or place on each Placeable at chosen coordinates.
Read the original → interview
- #jetpack-compose
- #custom-layout
- #measurepolicy
- #android
- #ui
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.