What you'll learn
A single Text is a start, but real screens arrange many composables. Compose gives you three fundamental layout composables — Column, Row, and Box — and almost every screen you'll ever build is some nesting of these three.
By the end you'll be able to:
- Stack composables vertically, horizontally, and on top of each other
- Control spacing with
ArrangementandAlignment - Distribute space with
weightandSpacer - Nest layouts to build a screen
Column, Row & Box
Each layout arranges its children differently:
| Layout | Arranges children |
|---|---|
Column | Vertically, top to bottom |
Row | Horizontally, side by side |
Box | Stacked on top of each other (for overlays) |
You nest them to build anything: a Column for a screen, a Row inside it for a button bar, and so on. Here's a small profile block combining a Column and a Row:
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
Text("Profile", fontWeight = FontWeight.Bold)
Text("Ada Lovelace")
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
Text("Follow")
Text("Message")
}
}Box is for layering — its children stack in the order written, so you can place text over an image or a badge in a corner:
Box(contentAlignment = Alignment.Center) {
Image(painter = avatar, contentDescription = null)
Text("Online", color = Color.White) // drawn on top of the image
}Arrangement & Alignment
Two properties position children within a layout — and the naming follows the layout's direction:
- Arrangement controls spacing along the main axis — vertical for a Column, horizontal for a Row. Options include
Arrangement.Center,SpaceBetween,SpaceEvenly, andspacedBy(8.dp)for even gaps. - Alignment controls the cross axis — so a Column takes
horizontalAlignmentand a Row takesverticalAlignment.
Tip
Arrangement.spacedBy(8.dp) is the cleanest way to put even gaps between children — much better than adding padding to each item. It's the Compose equivalent of CSS gap.Spacer & weight
Two tools distribute space. A Spacer(Modifier.height(16.dp)) inserts a fixed gap. More powerfully, Modifier.weight(1f) on a child makes it expand to fill the remaining space — give two children weight(1f) each and they split the row equally, or put weight(1f) on a Spacer to push a button to the far end (like a toolbar).
Recap & quick check
Key takeaways
- Column stacks children vertically, Row horizontally, and Box layers them on top of each other.
- Nest Columns, Rows, and Boxes to build any screen.
- Arrangement spaces children on the main axis; Alignment positions them on the cross axis.
- Arrangement.spacedBy(8.dp) adds even gaps — Compose's version of CSS gap.
- Modifier.weight(1f) makes a child expand to fill remaining space; Spacer inserts fixed gaps.
Quick check
1. Which layout arranges its children vertically?
2. Which layout do you use to overlay one composable on another?
3. In a Column, which property controls the vertical spacing of children?
4. What does Modifier.weight(1f) do to a child in a Row?
5. What's the cleanest way to put even gaps between children?
You can lay out whole screens now. Next we bring them to life visually with images, icons, and resources.