androidx.compose.foundation.layout

GridSince 1.11Experimental

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

Grid places children in rows and columns, like a table or a CSS grid. You set the sizes of the columns and rows once; children fill the cells in order, or you place them in a given cell.

It is new and experimental: add @OptIn(ExperimentalGridApi::class). Its API may still change.

Grid(
    config = {
        column(120.dp)   // a fixed column
        column(1.fr)     // takes the rest
        row(48.dp)
        row(48.dp)
        gap(8.dp)
    },
) {
    Text("Name")
    Text("Ada Lovelace")
    Text("Notes", Modifier.gridItem(row = 2, column = 1))
    Text("First programmer", Modifier.gridItem(row = 2, column = 2))
}

Use Grid for a fixed layout, like a form or a dashboard. For a long scrolling list of items, use LazyVerticalGrid instead.

Read more

ParametersExperimental

@Composable
fun Grid(
    config: GridConfigurationScope.() -> Unit,
    modifier: Modifier = Modifier,
    content: @Composable GridScope.() -> Unit,
)

config: GridConfigurationScope.() -> UnitRequired

The columns, rows and gaps. A lambda in GridConfigurationScope: call column(...), row(...) and gap(...) in order.

modifier: ModifierOptional

Default: Modifier

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

content: @Composable GridScope.() -> UnitRequired

The children. Place one with Modifier.gridItem(row, column), or let it fill the next cell.