androidx.compose.foundation.layout
Row
Composable function · from org.jetbrains.compose.foundation:foundation-layout:1.12.2
Row places its children next to each other, from start to end. Column places them one under the other, from top to bottom. Most screens are made of these two.
Row(
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Icon(Icons.Filled.Star, contentDescription = null)
Text("Favorites")
}
Two ideas set where children go:
- Arrangement is along the main direction: horizontal in a
Row, vertical in aColumn. It spreads the children or puts space between them. SeeArrangement. - Alignment is across it: vertical in a
Row, horizontal in aColumn. It lines the children up at the top, center or bottom. SeeAlignment.
Inside the content, children get extra modifiers from RowScope or ColumnScope:
Modifier.weight(1f)shares the free space between children. See the Modifier guide.Modifier.align(...)aligns one child differently from the others.
A Row or Column doesn't scroll. Add Modifier.horizontalScroll(...) or Modifier.verticalScroll(...), or use LazyRow or LazyColumn for long lists.
When children don't fit in one line, use FlowRow: it wraps to the next line.
Parameters
@Composable
fun Row(
modifier: Modifier = Modifier,
horizontalArrangement: Arrangement.Horizontal = Arrangement.Start,
verticalAlignment: Alignment.Vertical = Alignment.Top,
content: @Composable RowScope.() -> Unit,
)
modifier: ModifierOptional
modifier: ModifierOptionalDefault: Modifier
Changes size, padding, or position. See the Modifier guide.
horizontalArrangement: Arrangement.HorizontalOptional
horizontalArrangement: Arrangement.HorizontalOptionalDefault: Arrangement.Start
How children are spread from start to end. Arrangement.spacedBy(8.dp) puts 8 dp between them; SpaceBetween pushes the first and last to the edges.
In a Row this is the main direction. The space is only visible when the Row is wider than its children, for example with fillMaxWidth().
verticalAlignment: Alignment.VerticalOptional
verticalAlignment: Alignment.VerticalOptionalDefault: Alignment.Top
How children line up vertically: Alignment.Top, CenterVertically or Bottom.
content: @Composable RowScope.() -> UnitRequired
content: @Composable RowScope.() -> UnitRequiredThe children. Each composable you call inside is one child, in order.
Linear layouts
RowColumn