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

StaggeredGridCells.Adaptive

public final class StaggeredGridCells.Adaptive implements StaggeredGridCells


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.

For example, for the vertical LazyVerticalStaggeredGrid Adaptive(20.dp) would mean that there will be as many columns as possible and every column will be at least 20.dp and all the columns will have equal width. If the screen is 88.dp wide then there will be 4 columns 22.dp each.

Summary

Public constructors

Adaptive(@NonNull Dp minSize)

Public methods

@NonNull int[]
calculateCrossAxisCellSizes(
    @NonNull Density receiver,
    int availableSize,
    int spacing
)

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

boolean
equals(Object other)
int

Public constructors

Adaptive

public Adaptive(@NonNull Dp minSize)

Public methods

calculateCrossAxisCellSizes

public @NonNull int[] calculateCrossAxisCellSizes(
    @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 staggered 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 LazyVerticalStaggeredGrid.

int spacing

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

equals

public boolean equals(Object other)

hashCode

public int hashCode()