tezvyn:

Build a custom layout in Jetpack Compose

Source: interviewintermediate

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

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.

Build a custom layout in Jetpack Compose · Tezvyn