SnapPosition

Interface

Common
interface SnapPosition

Describes the snapping positioning (i.e. final positioning after snapping animation finishes) of a given snap item in its containing layout.

Functions

fun position(
        layoutSize: Int,
        itemSize: Int,
        beforeContentPadding: Int,
        afterContentPadding: Int,
        itemIndex: Int,
        itemCount: Int,
    ): Int

Calculates the snap position where items will be aligned to in a snapping container. For instance, if SnapPosition.Center is used, once the snapping finishes the center of one of the items in the snapping container will be aligned exactly to the center of the snapping container, that is because the value returned by position was calculated as such a way that when one applies it to the item's current offset it will generate that final positioning.

The reference point is with respect to the start of the layout (including the content padding)

Parameters

layoutSizeThe main axis layout size within which an item can be positioned.
itemSizeThe main axis size for the item being positioned within this snapping layout.
beforeContentPaddingThe content padding in pixels applied before this Layout's content.
afterContentPaddingThe content padding in pixels applied after this Layout's content.
itemIndexThe index of the item being positioned.
itemCountThe total amount of items in the snapping container.

Returns

The offset of the snap position where items will be aligned to in a snapping container.