PagedSnapHelper

open class PagedSnapHelper
kotlin.Any
   ↳ 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 Unit
attachToRecyclerView(recyclerView: RecyclerView?)

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

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

open Boolean
isAtStart(layoutManager: LayoutManager!)

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

open Boolean
isAtEnd(layoutManager: LayoutManager!)

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

open View?
findSnapView(layoutManager: LayoutManager!)

Finds the view to snap to.

open IntArray!
calculateDistanceToFinalSnap(layoutManager: LayoutManager, targetView: View)

Protected methods
open SmoothScroller!
createScroller(layoutManager: LayoutManager!)

Returns a scroller specific to this PagedSnapHelper.

Public constructors

<init>

PagedSnapHelper(context: Context!)

Public methods

attachToRecyclerView

open fun attachToRecyclerView(recyclerView: RecyclerView?): Unit

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.

isAtStart

open fun isAtStart(layoutManager: LayoutManager!): Boolean

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

isAtEnd

open fun isAtEnd(layoutManager: LayoutManager!): Boolean

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

findSnapView

open fun findSnapView(layoutManager: 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 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.

calculateDistanceToFinalSnap

open fun calculateDistanceToFinalSnap(layoutManager: LayoutManager, targetView: View): IntArray!

Protected methods

createScroller

protected open fun createScroller(layoutManager: LayoutManager!): SmoothScroller!

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

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