-
public class PagerSnapHelper extends SnapHelper
Implementation of the SnapHelper supporting pager style snapping in either vertical or horizontal orientation.
PagerSnapHelper can help achieve a similar behavior to androidx.viewpager.widget.ViewPager. Set both RecyclerView and the items of the RecyclerView.Adapter to have MATCH_PARENT height and width and then attach PagerSnapHelper to the RecyclerView using attachToRecyclerView.
-
-
Method Summary
Modifier and Type Method Description Array<int>
calculateDistanceToFinalSnap(@NonNull() RecyclerView.LayoutManager layoutManager, @NonNull() View targetView)
Override this method to snap to a particular point within the target view or the containerview 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. -
-
Method Detail
-
calculateDistanceToFinalSnap
@Nullable() Array<int> calculateDistanceToFinalSnap(@NonNull() RecyclerView.LayoutManager layoutManager, @NonNull() View targetView)
Override this method to snap to a particular point within the target view or the containerview on any axis.
This method is called when the SnapHelper has intercepted a fling and it needsto know the exact distance required to scroll by in order to snap to the target view.
- Parameters:
layoutManager
- the RecyclerView.LayoutManager associated with the attachedRecyclerViewtargetView
- the target view that is chosen as the view to snap
-
findSnapView
@Nullable() View findSnapView(RecyclerView.LayoutManager layoutManager)
Override this method to provide a particular target view for snapping.
This method is called when the SnapHelper is ready to start snapping and requiresa target view to snap to. It will be explicitly called when the scroll state becomes idleafter a scroll. It will also be called when the SnapHelper is preparing to snapafter a fling and requires a reference view from the current set of child views.
If this method returns
{@code null}
, SnapHelper will not snap to any view.- Parameters:
layoutManager
- the RecyclerView.LayoutManager associated with the attachedRecyclerView
-
findTargetSnapPosition
int findTargetSnapPosition(RecyclerView.LayoutManager layoutManager, int velocityX, int velocityY)
Override to provide a particular adapter target position for snapping.
- Parameters:
layoutManager
- the RecyclerView.LayoutManager associated with the attachedRecyclerViewvelocityX
- fling velocity on the horizontal axisvelocityY
- fling velocity on the vertical axis
-
-
-
-