StickyHeaderSnapHelper

class StickyHeaderSnapHelper(adapter: ListGroupItemsCollection<out ListGroupItem>, maxFlingVelocityPx: Int?, createScroller: (Context) -> Scroller) : LinearSnapHelper

A LinearSnapHelper, which should be used with ListGroupItemsCollection to supports sticky headers in vertical orientation. To have the sticky header in the RecyclerView, StickyHeaderDecoration needs be added to it. In the normal situation, the implementation will snap the RecyclerView to the top. It will find the target view and its top will be snapped to the bottom of the header. However, if the last item in the RecyclerView is visible and it is more close to the bottom than to the top, the RecyclerView will be snapped to the bottom instead of to the top.

Parameters

adapter

The adapter is used to snap headers correctly.

maxFlingVelocityPx

The maximum fling velocity. Set it to limit the scroll range. If not set, RecyclerView.getMaxFlingVelocity is used.

createScroller

An optionally provided method to create a Scroller that is used in calculateScrollDistance.

Constructors

Link copied to clipboard
fun StickyHeaderSnapHelper(adapter: ListGroupItemsCollection<out ListGroupItem>, maxFlingVelocityPx: Int? = null, createScroller: (Context) -> Scroller = { Scroller(it, DecelerateInterpolator()) })

Inherited properties

Link copied to clipboard
val mRecyclerView: RecyclerView

Functions

Link copied to clipboard
open override fun attachToRecyclerView(recyclerView: RecyclerView?)
Link copied to clipboard
open override fun calculateDistanceToFinalSnap(layoutManager: RecyclerView.LayoutManager, targetView: View): IntArray

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.

Link copied to clipboard
open override fun calculateScrollDistance(velocityX: Int, velocityY: Int): IntArray

Calculates the estimated scroll distance in each direction given velocities on both axes. This method is overridden to constrain velocityY to the value of maxFlingVelocityPx.

Link copied to clipboard
open override fun findSnapView(layoutManager: RecyclerView.LayoutManager): View?

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 scrolling. 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. This method is overridden to find the closest view to the top or sticky header.

Inherited functions

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override fun findTargetSnapPosition(p0: RecyclerView.LayoutManager, p1: Int, p2: Int): Int
Link copied to clipboard
open override fun onFling(p0: Int, p1: Int): Boolean
Link copied to clipboard
open fun snapToTargetExistingView()