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

SnapLayoutInfoProvider

@ExperimentalFoundationApi
public interface SnapLayoutInfoProvider


Provides information about the layout that is using a SnapFlingBehavior. The provider should give the following information:

  1. Snapping bounds, the previous and the next snap position offset.

  2. Snap Step Size, the minimum size that the SnapFlingBehavior can animate.

  3. Approach offset calculation, an offset to be consumed before snapping to a defined bound.

Summary

Public methods

abstract float
calculateApproachOffset(@NonNull Density receiver, float initialVelocity)

Calculate the distance to navigate before settling into the next snapping bound.

abstract float

The minimum offset that snapping will use to animate.(e.g. an item size)

abstract float
calculateSnappingOffset(@NonNull Density receiver, float currentVelocity)

Given a target placement in a layout, the snapping offset is the next snapping position this layout can be placed in.

Public methods

calculateApproachOffset

abstract float calculateApproachOffset(@NonNull Density receiver, float initialVelocity)

Calculate the distance to navigate before settling into the next snapping bound.

Parameters
float initialVelocity

The current fling movement velocity. You can use this tho calculate a velocity based offset.

calculateSnapStepSize

abstract float calculateSnapStepSize(@NonNull Density receiver)

The minimum offset that snapping will use to animate.(e.g. an item size)

calculateSnappingOffset

abstract float calculateSnappingOffset(@NonNull Density receiver, float currentVelocity)

Given a target placement in a layout, the snapping offset is the next snapping position this layout can be placed in. If this is a short snapping, currentVelocity is guaranteed to be 0.If it is a long snapping, this method will be called after calculateApproachOffset.

Parameters
float currentVelocity

The current fling movement velocity. This may change throughout the fling animation.