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))
}
- Column and row sizes can be fixed (
120.dp), a share of the free space (1.fr,2.fr), or a percentage. - Children without
Modifier.gridItemfill the next free cell. - Row and column numbers start at 1. Negative numbers count from the end.
gridItemcan also span cells:rowSpan,columnSpan.
Use Grid for a fixed layout, like a form or a dashboard. For a long scrolling list of items, use LazyVerticalGrid instead.
Read more
- Grid: get started (Android Developers). Also covers container and item properties.
ParametersExperimental
@Composable
fun Grid(
config: GridConfigurationScope.() -> Unit,
modifier: Modifier = Modifier,
content: @Composable GridScope.() -> Unit,
)
config: GridConfigurationScope.() -> UnitRequired
config: GridConfigurationScope.() -> UnitRequiredThe columns, rows and gaps. A lambda in GridConfigurationScope: call column(...), row(...) and gap(...) in order.
modifier: ModifierOptional
modifier: ModifierOptionalDefault: Modifier
Changes size, padding, or position. See the Modifier guide.