GridScope
@LayoutScopeMarker
@JvmDefaultWithCompatibility
@ExperimentalGridApi
interface GridScope
Scope for the children of Grid.
Functions
fun Modifier.gridItem(
@AndroidXIntRange(from = -MaxGridIndex.toLong(), to = MaxGridIndex.toLong())
row: Int = GridIndexUnspecified,
@AndroidXIntRange(from = -MaxGridIndex.toLong(), to = MaxGridIndex.toLong())
column: Int = GridIndexUnspecified,
@AndroidXIntRange(from = 1) rowSpan: Int = 1,
@AndroidXIntRange(from = 1) columnSpan: Int = 1,
alignment: Alignment = Alignment.TopStart,
): Modifier
Configures the position, span, and alignment of an element within a Grid layout.
Apply this modifier to direct children of a Grid composable.
Default Behavior: If this modifier is not applied to a child, the child will be
automatically placed in the next available cell (spanning 1 row and 1 column) according to
the configured GridFlow.
Indexing: Grid row and column indices are 1-based.
- Positive values count from the start (1 is the first row/column).
- Negative values count from the end (-1 is the last explicitly defined row/column).
Auto-placement: If row or column are left to their default value
(GridIndexUnspecified), the Grid layout will automatically place the item based on the
configured GridFlow.
Parameters
| row | The specific 1-based row index to place the item in. Positive values count from the start (1 is the first row). Negative values count from the end (-1 is the last row). Must be within the range -MaxGridIndex, MaxGridIndex``. Defaults to GridIndexUnspecified for auto-placement. |
| column | The specific 1-based column index to place the item in. Positive values count from the start (1 is the first column). Negative values count from the end (-1 is the last column). Must be within the range -MaxGridIndex, MaxGridIndex``. Defaults to GridIndexUnspecified for auto-placement. |
| rowSpan | The number of rows this item should occupy. Must be greater than 0. Defaults to 1. |
| columnSpan | The number of columns this item should occupy. Must be greater than 0. Defaults to 1. |
| alignment | Specifies how the content should be aligned within the grid cell(s) it occupies. Defaults to Alignment.TopStart. |
fun Modifier.gridItem(
rows: IntRange,
columns: IntRange,
alignment: Alignment = Alignment.TopStart,
): Modifier
Configures the position, span, and alignment of an element within a Grid layout using
ranges.
This convenience overload converts IntRange inputs into row/column indices and spans.
Equivalence:
rows = 4..5maps torow = 4,rowSpan = 2.columns = 1..1maps tocolumn = 1,columnSpan = 1.
Modifier.gridItem(rows = 2..3, columns = 1..2) is functionally equivalent to
Modifier.gridItem(row = 2, rowSpan = 2, column = 1, columnSpan = 2).
Parameters
| rows | The range of rows to occupy (e.g., 1..2). The start determines the row index, and the size of the range determines the span. |
| columns | The range of columns to occupy (e.g., 1..3). The start determines the column index, and the size of the range determines the span. |
| alignment | Specifies how the content should be aligned within the grid cell(s). Defaults to Alignment.TopStart. |