# GridTrackSize

Artifact: [androidx.compose.foundation:foundation-layout](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/layout/Grid.kt+class:androidx.compose.foundation.layout.GridTrackSize) Added in [1.11.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.11.0) Common/AllAndroid/JVM
- Cmn

  ```
  value class GridTrackSize : GridTrackSpec
  ```

*** ** * ** ***

Defines the size of a track (a row or a column) in a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/Grid.composable#Grid(kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Function1)`.

Use the companion functions (e.g., `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#Fixed(androidx.compose.ui.unit.Dp)`, `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#Flex(androidx.compose.foundation.layout.Fr)`) to create instances.

## Summary

| ### Public companion functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#Fixed(androidx.compose.ui.unit.Dp)(size: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp)` A track with a fixed `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` size. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#Flex(androidx.compose.foundation.layout.Fr)(weight: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0) https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/Fr)` A flexible track that takes a share of the **remaining** space in the grid after non-flexible tracks (like `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#Fixed(androidx.compose.ui.unit.Dp)` and `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#Percentage(kotlin.Float)`) are allocated. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#MinMax(androidx.compose.ui.unit.Dp,androidx.compose.foundation.layout.Fr)(min: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp, max: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0) https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/Fr)` A flexible track with an explicitly defined minimum base size and a flexible maximum size. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#Percentage(kotlin.Float)(value: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` A track sized as a percentage of the **total** available size of the grid container. | Cmn |

| ### Public companion properties |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#Auto()` A track that behaves as minmax(min-content, max-content). | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#MaxContent()` A track that sizes itself to fit the maximum intrinsic size of its contents. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#MinContent()` A track that sizes itself to fit the minimum intrinsic size of its contents. | Cmn |

| ### Public functions |
|---|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#toString()()` | Cmn |

## Public companion functions

### Fixed

Cmn Added in [1.11.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.11.0)

```
fun Fixed(size: Dp): GridTrackSize
```

A track with a fixed `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` size.

| Parameters |
|---|---|
| `size: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` | The size of the track. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize.Companion#Fixed(androidx.compose.ui.unit.Dp)` is negative or `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp#Unspecified()`. |

### Flex

Cmn Added in [1.11.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.11.0)

```
fun Flex(weight: @FloatRange(from = 0.0) Fr): GridTrackSize
```

A flexible track that takes a share of the **remaining** space in the grid after non-flexible tracks (like `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#Fixed(androidx.compose.ui.unit.Dp)` and `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#Percentage(kotlin.Float)`) are allocated.

**Intrinsic Sizing:** By default, a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#Flex(androidx.compose.foundation.layout.Fr)` track behaves like CSS `1fr` (which implies `minmax(min-content, <weight>fr)`). Before distributing the remaining space, it queries the minimum intrinsic size (`min-content`) of its children to establish a base size and ensure content is not crushed.

Jetpack Compose strictly forbids querying the intrinsic size of a `SubcomposeLayout` (such as `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/LazyColumn.composable#LazyColumn(androidx.compose.ui.Modifier,androidx.compose.foundation.lazy.LazyListState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.layout.Arrangement.Vertical,androidx.compose.ui.Alignment.Horizontal,androidx.compose.foundation.gestures.FlingBehavior,kotlin.Boolean,androidx.compose.foundation.OverscrollEffect,kotlin.Function1)` or `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/LazyRow.composable#LazyRow(androidx.compose.ui.Modifier,androidx.compose.foundation.lazy.LazyListState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.layout.Arrangement.Horizontal,androidx.compose.ui.Alignment.Vertical,androidx.compose.foundation.gestures.FlingBehavior,kotlin.Boolean,androidx.compose.foundation.OverscrollEffect,kotlin.Function1)`). Placing a lazy list directly inside a standard `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#Flex(androidx.compose.foundation.layout.Fr)` track will result in an `IllegalStateException` crash. To safely place lazy lists in a flexible track, use `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#MinMax(androidx.compose.ui.unit.Dp,androidx.compose.foundation.layout.Fr)` instead.

| Parameters |
|---|---|
| `weight: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0) https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/Fr` | The flexible weight. Remaining space is distributed proportionally to this weight divided by the sum of all flex weights. Must be non-negative. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize.Companion#Flex(androidx.compose.foundation.layout.Fr)` is negative. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#MinMax(androidx.compose.ui.unit.Dp,androidx.compose.foundation.layout.Fr)` |   |

### MinMax

Cmn Added in [1.11.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.11.0)

```
fun MinMax(min: Dp, max: @FloatRange(from = 0.0) Fr): GridTrackSize
```

A flexible track with an explicitly defined minimum base size and a flexible maximum size. Conceptually, this behaves identically to the CSS Grid `minmax(min, max)` function.

**Difference from `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#Flex(androidx.compose.foundation.layout.Fr)`:** While a standard `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#Flex(androidx.compose.foundation.layout.Fr)` track inherently queries the `min-content` intrinsic size of its children to determine its minimum base size, `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#MinMax(androidx.compose.ui.unit.Dp,androidx.compose.foundation.layout.Fr)` strictly uses the provided `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize.Companion#MinMax(androidx.compose.ui.unit.Dp,androidx.compose.foundation.layout.Fr)` size.

**Usage with Lazy Lists:** Because `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#MinMax(androidx.compose.ui.unit.Dp,androidx.compose.foundation.layout.Fr)` relies on a predefined `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize.Companion#MinMax(androidx.compose.ui.unit.Dp,androidx.compose.foundation.layout.Fr)` size (e.g., `0.dp`), it entirely bypasses the intrinsic measurement pass. This makes it the **required** choice when placing `SubcomposeLayout`-backed components (such as `LazyColumn` or `LazyRow`) inside a flexible grid track, as these components will crash if their intrinsic sizes are queried.

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Grid
import androidx.compose.foundation.layout.GridTrackSize
import androidx.compose.foundation.layout.columns
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

Grid(
    modifier = Modifier.fillMaxSize().padding(16.dp),
    config = {
        column(120.dp) // Sidebar width
        column(minmax(0.dp, 1.fr)) // Content width

        row(60.dp) // Header height
        // IMPORTANT:
        // Flex track '1.fr' queries child intrinsic sizes. Since SubcomposeLayouts
        // (like LazyColumn) crash on intrinsic queries, we MUST use 'GridTrackSize.MinMax' with
        // an explicit minimum size (0.dp) to bypass the measurement crash safely!
        row(minmax(0.dp, 1.fr))

        gap(16.dp)
    },
) {
    // Top Header spanning both columns
    Box(
        Modifier.gridItem(row = 1, column = 1, columnSpan = 2)
            .background(Color.DarkGray)
            .fillMaxSize(),
        contentAlignment = Alignment.Center,
    ) {
        Text("App Header", color = Color.White)
    }

    // Left Sidebar
    Box(
        Modifier.gridItem(row = 2, column = 1).background(Color.LightGray).fillMaxSize(),
        contentAlignment = Alignment.Center,
    ) {
        Text("Navigation")
    }

    // Scrollable LazyColumn safely constrained in the flex area
    LazyColumn(
        modifier = Modifier.gridItem(row = 2, column = 2).fillMaxSize(),
        verticalArrangement = Arrangement.spacedBy(8.dp),
    ) {
        items(50) { index ->
            Box(Modifier.fillMaxWidth().background(Color(0xFFE0E0FF)).padding(16.dp)) {
                Text("Scrollable Content #$index")
            }
        }
    }
}
```

| Parameters |
|---|---|
| `min: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` | The explicit minimum fixed base size (e.g., `0.dp`). |
| `max: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0) https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/Fr` | The maximum flexible distribution weight (e.g., `1.fr`). |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize.Companion#MinMax(androidx.compose.ui.unit.Dp,androidx.compose.foundation.layout.Fr)` is negative or `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize.Companion#MinMax(androidx.compose.ui.unit.Dp,androidx.compose.foundation.layout.Fr)` is negative. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize#Flex(androidx.compose.foundation.layout.Fr)` |   |

### Percentage

Cmn Added in [1.11.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.11.0)

```
fun Percentage(value: @FloatRange(from = 0.0) Float): GridTrackSize
```

A track sized as a percentage of the **total** available size of the grid container. **Note:** In this implementation, percentages are calculated based on the **remaining available space after gaps** . This differs from the W3C CSS Grid spec, where percentages are based on the container size regardless of gaps. This behavior prevents unexpected overflows when mixing gaps and percentages (e.g., `50%` + `50%` + `gap` will fit perfectly here, but would overflow in CSS).

| Parameters |
|---|---|
| `value: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The percentage of the container size. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridTrackSize.Companion#Percentage(kotlin.Float)` is negative. |

## Public companion properties

### Auto

Cmn

```
val Auto: GridTrackSize
```

A track that behaves as minmax(min-content, max-content). It occupies at least its minimum content size, and grows to fit its maximum content size if space is available.

### MaxContent

Cmn

```
val MaxContent: GridTrackSize
```

A track that sizes itself to fit the maximum intrinsic size of its contents.

### MinContent

Cmn

```
val MinContent: GridTrackSize
```

A track that sizes itself to fit the minimum intrinsic size of its contents.

## Public functions

### toString

Cmn

```
open fun toString(): String
```