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

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 functions

Float

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

Cmn
Float

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

Cmn
Float

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

Cmn

Public functions

calculateApproachOffset

fun Density.calculateApproachOffset(initialVelocity: Float): Float

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

Parameters
initialVelocity: Float

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

calculateSnapStepSize

fun Density.calculateSnapStepSize(): Float

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

calculateSnappingOffset

fun Density.calculateSnappingOffset(currentVelocity: Float): Float

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
currentVelocity: Float

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