androidx.compose.foundation.lazy.grid

LazyVerticalGrid

Composable function · from org.jetbrains.compose.foundation:foundation:1.12.2

A LazyVerticalGrid places items in columns and scrolls down. Like a LazyColumn, it only creates the items on screen.

LazyVerticalGrid(
    columns = GridCells.Adaptive(minSize = 120.dp),
    contentPadding = PaddingValues(16.dp),
    horizontalArrangement = Arrangement.spacedBy(8.dp),
    verticalArrangement = Arrangement.spacedBy(8.dp),
) {
    items(photos, key = { it.id }) { photo -> PhotoTile(photo) }
}

The number of columns comes from GridCells:

Items are added with item { } and items(list) { }, like in a lazy list. An item can span more columns: item(span = { GridItemSpan(maxLineSpan) }) { Header() } makes a full-width header.

In a staggered grid, items can have different heights, like a photo wall.

Parameters

@Composable
fun LazyVerticalGrid(
    columns: GridCells,
    modifier: Modifier = Modifier,
    state: LazyGridState = rememberLazyGridState(),
    contentPadding: PaddingValues = PaddingValues(0.dp),
    reverseLayout: Boolean = false,
    verticalArrangement: Arrangement.Vertical = if (!reverseLayout) Arrangement.Top else Arrangement.Bottom,
    horizontalArrangement: Arrangement.Horizontal = Arrangement.Start,
    flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(),
    userScrollEnabled: Boolean = true,
    overscrollEffect: OverscrollEffect? = rememberOverscrollEffect(),
    content: LazyGridScope.() -> Unit,
)

columns: GridCellsRequired

How many columns, and how wide. See GridCells above.

modifier: ModifierOptional

Default: Modifier

Changes size, padding, or position. See the Modifier guide.

state: LazyGridStateOptional

Default: rememberLazyGridState()

Reads and controls the scroll position. Create it with rememberLazyGridState().

contentPadding: PaddingValuesOptional

Default: PaddingValues(0.dp)

Space around all items, inside the scroll area.

reverseLayout: BooleanOptional

Default: false

Set to true to start from the other end.

verticalArrangement: Arrangement.VerticalOptional

Default: if (!reverseLayout) Arrangement.Top else Arrangement.Bottom

The space between rows.

horizontalArrangement: Arrangement.HorizontalOptional

Default: Arrangement.Start

The space between columns.

flingBehavior: FlingBehaviorOptional

Default: ScrollableDefaults.flingBehavior()

How the grid slows down after a swipe.

userScrollEnabled: BooleanOptional

Default: true

Set to false to stop the user from scrolling.

overscrollEffect: OverscrollEffect?OptionalSince 1.8

Default: rememberOverscrollEffect()

What shows when the user scrolls past the end. Pass null for none.

content: LazyGridScope.() -> UnitRequired

The items: calls to item and items.

Grid types