Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Building Screens with Jetpack Compose  ›  Lesson

Column, Row and Box

Column / Row 14 minColumn stacks children vertically, Row places them side by side, Box layers them on top of each other, and modifiers set size, padding and alignment.

Column, Row and Box

Each row in Sprout's plant list has a photo, a name, a date, and a small "thirsty" badge on the photo's corner. Almost every screen you will ever build is some nesting of three layouts: Column, Row and Box.

The rule

Column goes down, Row goes across, Box stacks on top.

  • Column places children one below another.
  • Row places children side by side.
  • Box places children on top of each other, like layers; later children are drawn above earlier ones.
Row(modifier = Modifier.padding(16.dp)) {
    Box {
        Image(painter = photo, contentDescription = plant.name)
        ThirstyBadge(Modifier.align(Alignment.TopEnd))
    }
    Spacer(Modifier.width(12.dp))
    Column {
        Text(plant.name)
        Text("Water on ${plant.nextDate}")
    }
}

Modifiers adjust any composable: size (fillMaxWidth(), size(48.dp)), spacing (padding), looks (background), behaviour (clickable). They are applied in order, so the order changes the result: padding then background leaves an uncoloured gap outside the colour, while background then padding colours the gap too.

Alignment comes from the parent: Column takes horizontalAlignment, Row takes verticalAlignment, and a child in a Box uses Modifier.align(...).

The shortcut

Read the design out loud: "X beside Y" means Row, "X above Y" means Column, "X on Y" means Box. Then nest from the outside in.

One row of Sprout's listStep 1 of 4
  1. Outermost relation

    Photo beside the text → Row.

Drills

Answer fast — trust the rule.

quick drill

Which layout places a label directly above a date?

quick drill

You want a badge drawn on top of a photo. Which layout?

quick drill

Inside a Box, how do you put one child in the top-right corner?

quick drill

Why do Modifier.padding(8.dp).background(Green) and Modifier.background(Green).padding(8.dp) look different?

Remember

  • Column goes down, Row goes across, Box stacks on top.
  • Beside → Row, above → Column, on → Box; nest from outside in.
  • Modifier order matters.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainLay out a plant row

Each plant in Sprout's list shows a photo on the left, and to its right the name above the next watering date. A small "thirsty" badge must sit on the top-right corner of the photo. Describe the layout composables you would nest, and why.