# RecyclerView.SmoothScroller

Artifact: [androidx.recyclerview:recyclerview](https://developer.android.com/jetpack/androidx/releases/recyclerview) [View Source](https://cs.android.com/search?q=file:androidx/recyclerview/widget/RecyclerView.java+class:androidx.recyclerview.widget.RecyclerView.SmoothScroller) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

*** ** * ** ***


```
public abstract class RecyclerView.SmoothScroller
```

<br />

Known direct subclasses [LinearSmoothScroller](https://developer.android.com/reference/androidx/recyclerview/widget/LinearSmoothScroller)

|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/LinearSmoothScroller` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller` implementation which uses a `https://developer.android.com/reference/android/view/animation/LinearInterpolator.html` until the target position becomes a child of the RecyclerView and then uses a `https://developer.android.com/reference/android/view/animation/DecelerateInterpolator.html` to slowly approach to target position. |

*** ** * ** ***

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 `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager#startSmoothScroll(androidx.recyclerview.widget.RecyclerView.SmoothScroller)`.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/LinearSmoothScroller` |   |

## Summary

| ### Nested types |
|---|
| `public class https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller.Action` Holds information about a smooth scroll request by a `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller`. |
| `public interface https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller.ScrollVectorProvider` An interface which is optionally implemented by custom `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager` to provide a hint to a `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller` about the location of the target position. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#SmoothScroller()()` |

| ### Public methods |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/graphics/PointF.html` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#computeScrollVectorForPosition(int)(int targetPosition)` Compute the scroll vector for a given target position. |
| `https://developer.android.com/reference/android/view/View.html` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#findViewByPosition(int)(int position)` |
| `int` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#getChildCount()()` |
| `int` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#getChildPosition(android.view.View)(https://developer.android.com/reference/android/view/View.html view)` |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#getLayoutManager()()` |
| `int` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#getTargetPosition()()` Returns the adapter position of the target item |
| `void` | `[instantScrollToPosition](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#instantScrollToPosition(int))(int position)` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller.Action#jumpTo(int)`. <br /> |
| `boolean` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#isPendingInitialRun()()` Returns true if SmoothScroller has been started but has not received the first animation callback yet. |
| `boolean` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#isRunning()()` |
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#setTargetPosition(int)(int targetPosition)` |

| ### Protected methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#normalize(android.graphics.PointF)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/PointF.html scrollVector)` Normalizes the vector. |
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#onChildAttachedToWindow(android.view.View)(https://developer.android.com/reference/android/view/View.html child)` |
| `abstract void` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#onSeekTargetStep(int,int,androidx.recyclerview.widget.RecyclerView.State,androidx.recyclerview.widget.RecyclerView.SmoothScroller.Action)( @https://developer.android.com/reference/androidx/annotation/Px int dx, @https://developer.android.com/reference/androidx/annotation/Px int dy, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.State state, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller.Action action )` RecyclerView will call this method each time it scrolls until it can find the target position in the layout. |
| `abstract void` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#onStart()()` Called when smooth scroll is started. |
| `abstract void` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#onStop()()` Called when smooth scroller is stopped. |
| `abstract void` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#onTargetFound(android.view.View,androidx.recyclerview.widget.RecyclerView.State,androidx.recyclerview.widget.RecyclerView.SmoothScroller.Action)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html targetView, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.State state, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller.Action action )` Called when the target position is laid out. |
| `final void` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#stop()()` Stops running the SmoothScroller in each animation callback. |

## Public constructors

### SmoothScroller

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public SmoothScroller()
```

## Public methods

### computeScrollVectorForPosition

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public @Nullable PointF computeScrollVectorForPosition(int targetPosition)
```

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 |
|---|---|
| `int targetPosition` | the position to which the scroller is scrolling |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/graphics/PointF.html` | the scroll vector for a given target position |

### findViewByPosition

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public View findViewByPosition(int position)
```

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager#findViewByPosition(int)` |   |

### getChildCount

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public int getChildCount()
```

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager#getChildCount()` |   |

### getChildPosition

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public int getChildPosition(View view)
```

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView#getChildLayoutPosition(android.view.View)` |   |

### getLayoutManager

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public @Nullable RecyclerView.LayoutManager getLayoutManager()
```

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager` | The LayoutManager to which this SmoothScroller is attached. Will return `null` after the SmoothScroller is stopped. |

### getTargetPosition

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public int getTargetPosition()
```

Returns the adapter position of the target item

| Returns |
|---|---|
| `int` | Adapter position of the target item or `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView#NO_POSITION()` if no target view is set. |

### instantScrollToPosition

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0) Deprecated in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public void [instantScrollToPosition](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#instantScrollToPosition(int))(int position)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller.Action#jumpTo(int)`.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView#scrollToPosition(int)` |   |

### isPendingInitialRun

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public boolean isPendingInitialRun()
```

Returns true if SmoothScroller has been started but has not received the first animation callback yet.

| Returns |
|---|---|
| `boolean` | True if this SmoothScroller is waiting to start |

### isRunning

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public boolean isRunning()
```

| Returns |
|---|---|
| `boolean` | True if SmoothScroller is currently active |

### setTargetPosition

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public void setTargetPosition(int targetPosition)
```

## Protected methods

### normalize

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
protected void normalize(@NonNull PointF scrollVector)
```

Normalizes the vector.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/PointF.html scrollVector` | The vector that points to the target scroll position |

### onChildAttachedToWindow

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
protected void onChildAttachedToWindow(View child)
```

### onSeekTargetStep

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
protected abstract void onSeekTargetStep(
    @Px int dx,
    @Px int dy,
    @NonNull RecyclerView.State state,
    @NonNull 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 `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller.Action` to define the next scroll.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Px int dx` | Last scroll amount horizontally |
| `@https://developer.android.com/reference/androidx/annotation/Px int dy` | Last scroll amount vertically |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.State state` | Transient state of RecyclerView |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller.Action action` | If you want to trigger a new smooth scroll and cancel the previous one, update this object. |

### onStart

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
protected abstract void onStart()
```

Called when smooth scroll is started. This might be a good time to do setup.

### onStop

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
protected abstract void onStop()
```

Called when smooth scroller is stopped. This is a good place to cleanup your state etc.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#stop()` |   |

### onTargetFound

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
protected abstract void onTargetFound(
    @NonNull View targetView,
    @NonNull RecyclerView.State state,
    @NonNull RecyclerView.SmoothScroller.Action action
)
```

Called when the target position is laid out. This is the last callback SmoothScroller will receive and it should update the provided `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller.Action` to define the scroll details towards the target view.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html targetView` | The view element which render the target position. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.State state` | Transient state of RecyclerView |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller.Action action` | Action instance that you should update to define final scroll action towards the targetView |

### stop

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
protected final void stop()
```

Stops running the SmoothScroller in each animation callback. Note that this does not cancel any existing `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller.Action` updated by `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#onTargetFound(android.view.View,androidx.recyclerview.widget.RecyclerView.State,androidx.recyclerview.widget.RecyclerView.SmoothScroller.Action)` or `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller#onSeekTargetStep(int,int,androidx.recyclerview.widget.RecyclerView.State,androidx.recyclerview.widget.RecyclerView.SmoothScroller.Action)`.