Compose Layout, Lists & Modifiers Interview Questions

UI › Compose UI

What are the basic layout composables in Compose, and how do they compare to View layouts?

What a strong answer covers: Column and Row arrange children vertically or horizontally like a LinearLayout, Box stacks them like a FrameLayout, and ConstraintLayout exists for complex relative positioning. Arrangement and Alignment control spacing and positioning; weight distributes space. LazyColumn and LazyRow replace RecyclerView. Compose layouts measure each child once, so nesting is cheaper than nested Views.

Why does the order of modifiers matter? Give an example.

What a strong answer covers: Modifiers wrap each other from first to last, each one affecting what follows. Modifier.padding(16.dp).background(Color.Red) puts the padding outside the red area, while background first then padding gives red behind the padding. Similarly, clickable before padding makes the padding clickable, and size before padding vs after changes the content size.

How do LazyColumn and keys work, and why should you provide a key?

What a strong answer covers: LazyColumn composes and lays out only visible items, like RecyclerView. Without a key, items are identified by position, so inserting or removing an item shifts state (remembered values, animations) onto the wrong items and scroll position can jump. items(list, key = { it.id }) gives each item a stable identity, preserves state through reorders, and enables animateItem. Also use contentType for heterogeneous lists to improve reuse.

How does layout work in Compose? Explain constraints, measure and place, and how you'd write a custom layout.

What a strong answer covers: Layout goes down and up the tree in a single pass: a parent passes constraints (min and max width and height) to each child, the child measures itself within them and reports a size, then the parent places children. Each child may be measured only once. Custom layouts use Layout(content) { measurables, constraints -> measure each, then layout(width, height) { placeable.place(x, y) } }, or Modifier.layout for a single element. Intrinsic measurements allow querying size before measuring.

Why might a LazyColumn scroll badly, and how would you track down the cause?

What a strong answer covers: Common causes: no keys, so items are rebuilt; unstable item parameters causing recomposition of every visible item; heavy work in item composables (formatting dates, decoding images, sorting); nesting a scrollable inside another in the same direction; reading scroll state in composition; and big images without sizing. Diagnose with a release build, the Layout Inspector's recomposition counts, composition tracing in Perfetto, and Macrobenchmark frame timing; fix with keys, contentType, stable models, remember, and Baseline Profiles.

Back to Compose Layout, Lists & Modifiers