Lesson 2
Column, Row and Box
Three layouts place almost everything in Compose: Column stacks elements
vertically, Row places them side by side, and Box layers them on top of
each other.
Column
A Column places its children below each other. Arrangement.spacedBy adds
the same space between them:
The children go inside the braces { } after the parentheses. This trailing lambda is how
every layout in Compose takes its content.
Row
A Row places its children side by side. Here a circle sits beside a
Column of two texts, and verticalAlignment centers them vertically:
Layouts nest inside each other, so a few Rows and Columns can build most
screens.
Box
A Box places its children on top of each other. contentAlignment sets where
they go, and Modifier.align moves a single child:
Arrangement and alignment
| Layout | Main direction | Other direction |
|---|---|---|
Column | verticalArrangement | horizontalAlignment |
Row | horizontalArrangement | verticalAlignment |
Box | contentAlignment, or Modifier.align on a child | |
Summary
Column: below each other.Row: side by side.Box: on top of each other.- Arrangement spaces children along the main direction; alignment positions them across it.
Fast Compose