public class LinearSnapHelper extends SnapHelper
SnapHelper
supporting snapping in either vertical or horizontal
orientation.
The implementation will snap the center of the target child view to the center of
the attached RecyclerView
. If you intend to change this behavior then override
SnapHelper.calculateDistanceToFinalSnap(android.support.v7.widget.RecyclerView.LayoutManager, android.view.View)
.
Constructor and Description |
---|
LinearSnapHelper() |
Modifier and Type | Method and Description |
---|---|
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.
|
View |
findSnapView(RecyclerView.LayoutManager layoutManager)
Override this method to provide a particular target view for snapping.
|
int |
findTargetSnapPosition(RecyclerView.LayoutManager layoutManager,
int velocityX,
int velocityY)
Override to provide a particular adapter target position for snapping.
|
attachToRecyclerView, calculateScrollDistance, onFling
public int[] calculateDistanceToFinalSnap(@NonNull RecyclerView.LayoutManager layoutManager, @NonNull View targetView)
SnapHelper
This method is called when the SnapHelper
has intercepted a fling and it needs
to know the exact distance required to scroll by in order to snap to the target view.
calculateDistanceToFinalSnap
in class SnapHelper
layoutManager
- the RecyclerView.LayoutManager
associated with the attached
RecyclerView
targetView
- the target view that is chosen as the view to snappublic int findTargetSnapPosition(RecyclerView.LayoutManager layoutManager, int velocityX, int velocityY)
SnapHelper
findTargetSnapPosition
in class SnapHelper
layoutManager
- the RecyclerView.LayoutManager
associated with the attached
RecyclerView
velocityX
- fling velocity on the horizontal axisvelocityY
- fling velocity on the vertical axisRecyclerView.NO_POSITION
if no snapping should happenpublic View findSnapView(RecyclerView.LayoutManager layoutManager)
SnapHelper
This method is called when the SnapHelper
is ready to start snapping and requires
a target view to snap to. It will be explicitly called when the scroll state becomes idle
after a scroll. It will also be called when the SnapHelper
is preparing to snap
after a fling and requires a reference view from the current set of child views.
If this method returns null
, SnapHelper will not snap to any view.
findSnapView
in class SnapHelper
layoutManager
- the RecyclerView.LayoutManager
associated with the attached
RecyclerView