Compose Unstyled 2.0 is out! Check the official announcement blog ->

A single layout component for horizontal and vertical stacks.

Installation

implementation("com.composables:composeunstyled-stack")

Anatomy

Stack {
}

Concepts

  • Stack renders children in one horizontal or vertical layout.
  • The weight() modifier distributes remaining space in the current stack orientation.

Code Examples

Creating a vertical stack

Use the orientation parameter to arrange content vertically:

Stack(orientation = StackOrientation.Vertical) {
  BasicText("One")
  BasicText("Two")
}

Adding space between items

Use the spacing parameter to add equal space between children:

Stack(spacing = 12.dp) {
  BasicText("One")
  BasicText("Two")
}

Aligning stack content

Use the mainAxisArrangement and crossAxisAlignment parameters to align children:

Stack(
  mainAxisArrangement = MainAxisArrangement.Center,
  crossAxisAlignment = CrossAxisAlignment.Center,
) {
  BasicText("One")
  BasicText("Two")
}

Weighting stack children

Use the weight() modifier inside Stack content to distribute remaining space:

Stack {
  BasicText(
    text = "Primary",
    modifier = Modifier.weight(1f),
  )
  BasicText("Secondary")
}

API Reference

Stack

Parameter Type Description
modifier Modifier Modifier to be applied to the Stack
orientation StackOrientation Controls whether children are laid out horizontally or vertically. Defaults to StackOrientation.Horizontal
mainAxisArrangement MainAxisArrangement Controls the arrangement of children along the main axis (horizontal for horizontal orientation, vertical for vertical orientation). Defaults to MainAxisArrangement.Start
crossAxisAlignment CrossAxisAlignment Controls the alignment of children on the cross axis (vertical for horizontal orientation, horizontal for vertical orientation). Defaults to CrossAxisAlignment.Start
spacing Dp Space between children. Ignored when using SpaceEvenly, SpaceBetween, or SpaceAround arrangements. Defaults to 0.dp
content StackScope.() -> Unit The composable content to be laid out within the Stack