# StaggeredGridCells

Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/lazy/staggeredgrid/LazyStaggeredGridCells.kt+class:androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.3.0) Common/All
- Cmn

  ```
  interface StaggeredGridCells
  ```
Known direct subclasses [StaggeredGridCells.Adaptive](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells.Adaptive), [StaggeredGridCells.FixedSize](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells.FixedSize), [StaggeredGridCells.Fixed](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells.Fixed)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells.Adaptive` | Defines a grid with as many rows or columns as possible on the condition that every cell has at least `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells.Adaptive#minSize()` space and all extra space distributed evenly. |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells.FixedSize` | Defines a grid with as many rows or columns as possible on the condition that every cell takes exactly `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells.FixedSize#size()` space. |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells.Fixed` | Defines a grid with fixed number of rows or columns. |

*** ** * ** ***

This class describes the count and the sizes of columns in vertical staggered grids, or rows in horizontal staggered grids.

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells.Adaptive : https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells` Defines a grid with as many rows or columns as possible on the condition that every cell has at least `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells.Adaptive#minSize()` space and all extra space distributed evenly. |
| `class https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells.Fixed : https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells` Defines a grid with fixed number of rows or columns. |
| `class https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells.FixedSize : https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells` Defines a grid with as many rows or columns as possible on the condition that every cell takes exactly `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells.FixedSize#size()` space. |

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density.https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells#(androidx.compose.ui.unit.Density).calculateCrossAxisCellSizes(kotlin.Int,kotlin.Int)(availableSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, spacing: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Calculates the number of cells and their cross axis size based on `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells#(androidx.compose.ui.unit.Density).calculateCrossAxisCellSizes(kotlin.Int,kotlin.Int)` and `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells#(androidx.compose.ui.unit.Density).calculateCrossAxisCellSizes(kotlin.Int,kotlin.Int)`. | Cmn |

## Public functions

### Density.calculateCrossAxisCellSizes

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/lazy/staggeredgrid/LazyStaggeredGridCells.kt+function:calculateCrossAxisCellSizes) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.3.0)

```
fun Density.calculateCrossAxisCellSizes(availableSize: Int, spacing: Int): IntArray
```

Calculates the number of cells and their cross axis size based on `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells#(androidx.compose.ui.unit.Density).calculateCrossAxisCellSizes(kotlin.Int,kotlin.Int)` and `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells#(androidx.compose.ui.unit.Density).calculateCrossAxisCellSizes(kotlin.Int,kotlin.Int)`.

For example, in vertical grids, `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/StaggeredGridCells#(androidx.compose.ui.unit.Density).calculateCrossAxisCellSizes(kotlin.Int,kotlin.Int)` is passed from the grid's `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/Arrangement.Horizontal`. The `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/Arrangement.Horizontal` will also be used to arrange items in a row if the grid is wider than the calculated sum of columns.

Note that the calculated cross axis sizes will be considered in an RTL-aware manner -- if the staggered grid is vertical and the layout direction is RTL, the first width in the returned list will correspond to the rightmost column.

| Parameters |
|---|---|
| `availableSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | available size on cross axis, e.g. width of `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/LazyVerticalStaggeredGrid.composable#LazyVerticalStaggeredGrid(androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells,androidx.compose.ui.Modifier,androidx.compose.foundation.lazy.staggeredgrid.LazyStaggeredGridState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.ui.unit.Dp,androidx.compose.foundation.layout.Arrangement.Horizontal,androidx.compose.foundation.gestures.FlingBehavior,kotlin.Boolean,androidx.compose.foundation.OverscrollEffect,androidx.compose.foundation.lazy.layout.LazyLayoutCacheWindow,kotlin.Function1)`. |
| `spacing: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | cross axis spacing, e.g. horizontal spacing for `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/LazyVerticalStaggeredGrid.composable#LazyVerticalStaggeredGrid(androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells,androidx.compose.ui.Modifier,androidx.compose.foundation.lazy.staggeredgrid.LazyStaggeredGridState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.ui.unit.Dp,androidx.compose.foundation.layout.Arrangement.Horizontal,androidx.compose.foundation.gestures.FlingBehavior,kotlin.Boolean,androidx.compose.foundation.OverscrollEffect,androidx.compose.foundation.lazy.layout.LazyLayoutCacheWindow,kotlin.Function1)`. The spacing is passed from the corresponding `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/Arrangement` param of the lazy grid. |