SmoothScroller
abstract class SmoothScroller
kotlin.Any | |
↳ | androidx.recyclerview.widget.RecyclerView.SmoothScroller |
Base class for smooth scrolling. Handles basic tracking of the target view position and provides methods to trigger a programmatic scroll.
An instance of SmoothScroller is only intended to be used once. You should create a new instance for each call to LayoutManager#startSmoothScroll(SmoothScroller)
.
Summary
Nested classes | |
---|---|
open |
Holds information about a smooth scroll request by a |
abstract |
An interface which is optionally implemented by custom |
Public constructors | |
---|---|
<init>() |
Public methods | |
---|---|
open PointF? |
computeScrollVectorForPosition(targetPosition: Int) Compute the scroll vector for a given target position. |
open View! |
findViewByPosition(position: Int) |
open Int | |
open Int |
getChildPosition(view: View!) |
open RecyclerView.LayoutManager? | |
open Int |
Returns the adapter position of the target item |
open Unit |
instantScrollToPosition(position: Int) |
open Boolean |
Returns true if SmoothScroller has been started but has not received the first animation callback yet. |
open Boolean | |
open Unit |
setTargetPosition(targetPosition: Int) |
Protected methods | |
---|---|
open Unit |
Normalizes the vector. |
open Unit |
onChildAttachedToWindow(child: View!) |
abstract Unit |
onSeekTargetStep(@Px dx: Int, @Px dy: Int, @NonNull state: RecyclerView.State, @NonNull action: RecyclerView.SmoothScroller.Action) RecyclerView will call this method each time it scrolls until it can find the target position in the layout. |
abstract Unit |
onStart() Called when smooth scroll is started. |
abstract Unit |
onStop() Called when smooth scroller is stopped. |
abstract Unit |
onTargetFound(@NonNull targetView: View, @NonNull state: RecyclerView.State, @NonNull action: RecyclerView.SmoothScroller.Action) Called when the target position is laid out. |
Unit |
stop() Stops running the SmoothScroller in each animation callback. |
Public constructors
<init>
SmoothScroller()
Public methods
computeScrollVectorForPosition
@Nullable open fun computeScrollVectorForPosition(targetPosition: Int): PointF?
Compute the scroll vector for a given target position.
This method can return null if the layout manager cannot calculate a scroll vector for the given position (e.g. it has no current scroll position).
Parameters | |
---|---|
targetPosition |
Int: the position to which the scroller is scrolling |
Return | |
---|---|
PointF? |
the scroll vector for a given target position |
getLayoutManager
@Nullable open fun getLayoutManager(): RecyclerView.LayoutManager?
Return | |
---|---|
RecyclerView.LayoutManager? |
The LayoutManager to which this SmoothScroller is attached. Will return null after the SmoothScroller is stopped. |
getTargetPosition
open fun getTargetPosition(): Int
Returns the adapter position of the target item
Return | |
---|---|
Int |
Adapter position of the target item or RecyclerView#NO_POSITION if no target view is set. |
instantScrollToPosition
open funinstantScrollToPosition(position: Int): Unit
Deprecated: Use Action#jumpTo(int)
.
See Also
isPendingInitialRun
open fun isPendingInitialRun(): Boolean
Returns true if SmoothScroller has been started but has not received the first animation callback yet.
Return | |
---|---|
Boolean |
True if this SmoothScroller is waiting to start |
Protected methods
normalize
protected open fun normalize(@NonNull scrollVector: PointF): Unit
Normalizes the vector.
Parameters | |
---|---|
scrollVector |
PointF: The vector that points to the target scroll position |
onSeekTargetStep
protected abstract fun onSeekTargetStep(
@Px dx: Int,
@Px dy: Int,
@NonNull state: RecyclerView.State,
@NonNull action: RecyclerView.SmoothScroller.Action
): Unit
RecyclerView will call this method each time it scrolls until it can find the target position in the layout.
SmoothScroller should check dx, dy and if scroll should be changed, update the provided Action
to define the next scroll.
Parameters | |
---|---|
dx |
Int: Last scroll amount horizontally |
dy |
Int: Last scroll amount vertically |
state |
RecyclerView.State: Transient state of RecyclerView |
action |
RecyclerView.SmoothScroller.Action: If you want to trigger a new smooth scroll and cancel the previous one, update this object. |
onStart
protected abstract fun onStart(): Unit
Called when smooth scroll is started. This might be a good time to do setup.
onStop
protected abstract fun onStop(): Unit
Called when smooth scroller is stopped. This is a good place to cleanup your state etc.
See Also
onTargetFound
protected abstract fun onTargetFound(
@NonNull targetView: View,
@NonNull state: RecyclerView.State,
@NonNull action: RecyclerView.SmoothScroller.Action
): Unit
Called when the target position is laid out. This is the last callback SmoothScroller will receive and it should update the provided Action
to define the scroll details towards the target view.
Parameters | |
---|---|
|