Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

PagedSnapHelper

open class PagedSnapHelper : LinearSnapHelper
kotlin.Any
   ↳ androidx.recyclerview.widget.RecyclerView.OnFlingListener
   ↳ androidx.recyclerview.widget.SnapHelper
   ↳ androidx.recyclerview.widget.LinearSnapHelper
   ↳ androidx.car.widget.PagedSnapHelper

Extension of a LinearSnapHelper that will snap to the start of the target child view to the start of the attached RecyclerView. The start of the view is defined as the top if the RecyclerView is scrolling vertically; it is defined as the left (or right if RTL) if the RecyclerView is scrolling horizontally.

Snapping may be disabled for views whose height is greater than that of the RecyclerView that contains them. In this case, the view will only be snapped to when it is first encountered. Otherwise, the user will be allowed to scroll freely through that view when it appears in the list. The snapping behavior will resume when the large view is scrolled off-screen.

Summary

Public constructors
<init>(context: Context!)

Public methods
open IntArray?
calculateDistanceToFinalSnap(@NonNull layoutManager: RecyclerView.LayoutManager, @NonNull targetView: View)

open IntArray!
calculateScrollDistance(velocityX: Int, velocityY: Int)

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

open Boolean

Returns true if the RecyclerView is completely displaying the last item.

open View?

Finds the view to snap to.

open Unit
attachToRecyclerView(@Nullable recyclerView: RecyclerView?)

open Boolean

Returns true if the RecyclerView is completely displaying the first item.

Protected methods
open RecyclerView.SmoothScroller?

Returns a scroller specific to this PagedSnapHelper.

Inherited functions

Public constructors

<init>

PagedSnapHelper(context: Context!)

Public methods

calculateDistanceToFinalSnap

open fun calculateDistanceToFinalSnap(@NonNull layoutManager: RecyclerView.LayoutManager, @NonNull targetView: View): IntArray?

calculateScrollDistance

open fun calculateScrollDistance(velocityX: Int, velocityY: Int): IntArray!

Calculate the estimated scroll distance in each direction given velocities on both axes. This method will clamp the maximum scroll distance so that a single fling will never scroll more than one page.

Parameters
velocityX Int: Fling velocity on the horizontal axis.
velocityY Int: Fling velocity on the vertical axis.
Return
IntArray!: An array holding the calculated distances in x and y directions respectively.

isAtEnd

open fun isAtEnd(layoutManager: RecyclerView.LayoutManager!): Boolean

Returns true if the RecyclerView is completely displaying the last item.

findSnapView

@Nullable open fun findSnapView(layoutManager: RecyclerView.LayoutManager!): View?

Finds the view to snap to. The view to snap to is the child of the LayoutManager that is closest to the start of the RecyclerView. The "start" depends on if the LayoutManager is scrolling horizontally or vertically. If it is horizontally scrolling, then the start is the view on the left (right if RTL). Otherwise, it is the top-most view.

Parameters
layoutManager RecyclerView.LayoutManager!: The current RecyclerView.LayoutManager for the attached RecyclerView.
Return
View?: The View closest to the start of the RecyclerView. Returns nullwhen:
  • there is no item; or
  • no visible item can fully fit in the containing RecyclerView; or
  • an item longer than containing RecyclerView is about to scroll out.

attachToRecyclerView

open fun attachToRecyclerView(@Nullable recyclerView: RecyclerView?): Unit

isAtStart

open fun isAtStart(layoutManager: RecyclerView.LayoutManager!): Boolean

Returns true if the RecyclerView is completely displaying the first item.

Protected methods

createScroller

protected open fun createScroller(layoutManager: RecyclerView.LayoutManager!): RecyclerView.SmoothScroller?

Returns a scroller specific to this PagedSnapHelper. This scroller is used for all smooth scrolling operations, including flings.

Parameters
layoutManager RecyclerView.LayoutManager!: The RecyclerView.LayoutManager associated with the attached RecyclerView.
Return
RecyclerView.SmoothScroller?: a RecyclerView.SmoothScroller which will handle the scrolling.