GridTrackSize
@ExperimentalGridApi
value class GridTrackSize internal constructor(internal val encodedValue: Long) : GridTrackSpec
Defines the size of a track (a row or a column) in a Grid.
Use the companion functions (e.g., Fixed, Flex) to create instances.
Companion Object
Properties
val MinContent = pack(TypeMinContent, 0f)
A track that sizes itself to fit the minimum intrinsic size of its contents.
val MaxContent = pack(TypeMaxContent, 0f)
A track that sizes itself to fit the maximum intrinsic size of its contents.
val Auto = pack(TypeAuto, 0f)
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.
Methods
fun Fixed(size: Dp): GridTrackSize
A track with a fixed Dp size.
Parameters
| size | The size of the track. |
fun Percentage(@FloatRange(from = 0.0) value: 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 | The percentage of the container size. |
fun Flex(@FloatRange(from = 0.0) weight: Fr): GridTrackSize
A flexible track that takes a share of the remaining space in the grid after
non-flexible tracks (like Fixed and Percentage) are allocated.
Intrinsic Sizing: By default, a Flex 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 LazyColumn or
LazyRow). Placing a lazy list directly inside
a standard Flex track will result in an IllegalStateException crash. To safely place
lazy lists in a flexible track, use MinMax instead.
Parameters
| weight | The flexible weight. Remaining space is distributed proportionally to this weight divided by the sum of all flex weights. Must be non-negative. |
fun MinMax(min: Dp, @FloatRange(from = 0.0) max: 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 Flex: While a standard Flex track inherently queries the
min-content intrinsic size of its children to determine its minimum base size, MinMax
strictly uses the provided min size.
Usage with Lazy Lists: Because MinMax relies on a predefined min 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.
Parameters
| min | The explicit minimum fixed base size (e.g., 0.dp). |
| max | The maximum flexible distribution weight (e.g., 1.fr). |