added in version 25.1.0
belongs to Maven artifact com.android.support:recyclerview-v7:28.0.0-alpha1

SnapHelper

public abstract class SnapHelper
extends RecyclerView.OnFlingListener

java.lang.Object
   ↳ android.support.v7.widget.RecyclerView.OnFlingListener
     ↳ android.support.v7.widget.SnapHelper
Known Direct Subclasses


Class intended to support snapping for a RecyclerView.

SnapHelper tries to handle fling as well but for this to work properly, the RecyclerView.LayoutManager must implement the RecyclerView.SmoothScroller.ScrollVectorProvider interface or you should override onFling(int, int) and handle fling manually.

Summary

Public constructors

SnapHelper()

Public methods

void attachToRecyclerView(RecyclerView recyclerView)

Attaches the SnapHelper to the provided RecyclerView, by calling setOnFlingListener(RecyclerView.OnFlingListener).

abstract int[] calculateDistanceToFinalSnap(RecyclerView.LayoutManager layoutManager, View targetView)

Override this method to snap to a particular point within the target view or the container view on any axis.

int[] calculateScrollDistance(int velocityX, int velocityY)

Calculated the estimated scroll distance in each direction given velocities on both axes.

abstract View findSnapView(RecyclerView.LayoutManager layoutManager)

Override this method to provide a particular target view for snapping.

abstract int findTargetSnapPosition(RecyclerView.LayoutManager layoutManager, int velocityX, int velocityY)

Override to provide a particular adapter target position for snapping.

boolean onFling(int velocityX, int velocityY)

Override this to handle a fling given the velocities in both x and y directions.

Protected methods

RecyclerView.SmoothScroller createScroller(RecyclerView.LayoutManager layoutManager)

Creates a scroller to be used in the snapping implementation.

LinearSmoothScroller createSnapScroller(RecyclerView.LayoutManager layoutManager)

This method was deprecated in API level 26.1.0. use createScroller(LayoutManager) instead.

Inherited methods

From class android.support.v7.widget.RecyclerView.OnFlingListener
From class java.lang.Object