public abstract static class RecyclerView.SmoothScroller extends Object
Base class for smooth scrolling. Handles basic tracking of the target view position and provides methods to trigger a programmatic scroll.
LinearSmoothScroller
Modifier and Type | Class and Description |
---|---|
static class |
RecyclerView.SmoothScroller.Action
Holds information about a smooth scroll request by a
RecyclerView.SmoothScroller . |
static interface |
RecyclerView.SmoothScroller.ScrollVectorProvider
An interface which is optionally implemented by custom
RecyclerView.LayoutManager
to provide a hint to a RecyclerView.SmoothScroller about the location of the target position. |
Constructor and Description |
---|
SmoothScroller() |
Modifier and Type | Method and Description |
---|---|
View |
findViewByPosition(int position) |
int |
getChildCount() |
int |
getChildPosition(View view) |
RecyclerView.LayoutManager |
getLayoutManager() |
int |
getTargetPosition()
Returns the adapter position of the target item
|
void |
instantScrollToPosition(int position)
Deprecated.
|
boolean |
isPendingInitialRun()
Returns true if SmoothScroller has been started but has not received the first
animation
callback yet.
|
boolean |
isRunning() |
protected void |
normalize(PointF scrollVector)
Normalizes the vector.
|
protected void |
onChildAttachedToWindow(View child) |
protected abstract void |
onSeekTargetStep(int dx,
int dy,
RecyclerView.State state,
RecyclerView.SmoothScroller.Action action)
RecyclerView will call this method each time it scrolls until it can find the target
position in the layout.
|
protected abstract void |
onStart()
Called when smooth scroll is started.
|
protected abstract void |
onStop()
Called when smooth scroller is stopped.
|
protected abstract void |
onTargetFound(View targetView,
RecyclerView.State state,
RecyclerView.SmoothScroller.Action action)
Called when the target position is laid out.
|
void |
setTargetPosition(int targetPosition) |
protected void |
stop()
Stops running the SmoothScroller in each animation callback.
|
public void setTargetPosition(int targetPosition)
@Nullable public RecyclerView.LayoutManager getLayoutManager()
null
after the SmoothScroller is stopped.protected final void stop()
RecyclerView.SmoothScroller.Action
updated by
#onTargetFound(android.view.View, RecyclerView.State, SmoothScroller.Action)
or
#onSeekTargetStep(int, int, RecyclerView.State, SmoothScroller.Action)
.public boolean isPendingInitialRun()
public boolean isRunning()
public int getTargetPosition()
RecyclerView.NO_POSITION
if no target view is set.public int getChildPosition(View view)
public int getChildCount()
public View findViewByPosition(int position)
@Deprecated public void instantScrollToPosition(int position)
RecyclerView.SmoothScroller.Action.jumpTo(int)
.RecyclerView.scrollToPosition(int)
protected void onChildAttachedToWindow(View child)
protected void normalize(PointF scrollVector)
scrollVector
- The vector that points to the target scroll positionprotected abstract void onStart()
protected abstract void onStop()
stop()
protected abstract void onSeekTargetStep(int dx, int dy, RecyclerView.State state, RecyclerView.SmoothScroller.Action action)
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 RecyclerView.SmoothScroller.Action
to define the next scroll.
dx
- Last scroll amount horizontallydy
- Last scroll amount verticallystate
- Transient state of RecyclerViewaction
- If you want to trigger a new smooth scroll and cancel the previous one,
update this object.protected abstract void onTargetFound(View targetView, RecyclerView.State state, RecyclerView.SmoothScroller.Action action)
RecyclerView.SmoothScroller.Action
to define the scroll
details towards the target view.targetView
- The view element which render the target position.state
- Transient state of RecyclerViewaction
- Action instance that you should update to define final scroll action
towards the targetView