{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

GridCells

public interface GridCells

Known direct subclasses
GridCells.Adaptive

Defines a grid with as many rows or columns as possible on the condition that every cell has at least minSize space and all extra space distributed evenly.

GridCells.FixedSize

Defines a grid with as many rows or columns as possible on the condition that every cell takes exactly size space.

GridCells.Fixed

Defines a grid with fixed number of rows or columns.


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

Summary

Nested types

public final class GridCells.Adaptive implements GridCells

Defines a grid with as many rows or columns as possible on the condition that every cell has at least minSize space and all extra space distributed evenly.

public final class GridCells.Fixed implements GridCells

Defines a grid with fixed number of rows or columns.

public final class GridCells.FixedSize implements GridCells

Defines a grid with as many rows or columns as possible on the condition that every cell takes exactly size space.

Public methods

abstract @NonNull List<@NonNull Integer>
calculateCrossAxisCellSizes(
    @NonNull Density receiver,
    int availableSize,
    int spacing
)

Calculates the number of cells and their cross axis size based on availableSize and spacing.

Public methods

calculateCrossAxisCellSizes

abstract @NonNull List<@NonNull IntegercalculateCrossAxisCellSizes(
    @NonNull Density receiver,
    int availableSize,
    int spacing
)

Calculates the number of cells and their cross axis size based on availableSize and spacing.

For example, in vertical grids, spacing is passed from the grid's Arrangement.Horizontal. The 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 grid is vertical and the layout direction is RTL, the first width in the returned list will correspond to the rightmost column.

Parameters
int availableSize

available size on cross axis, e.g. width of LazyVerticalGrid.

int spacing

cross axis spacing, e.g. horizontal spacing for LazyVerticalGrid. The spacing is passed from the corresponding Arrangement param of the lazy grid.