# RecyclerView.SmoothScroller

# 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)

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.SmoothScroller "View this page in Java")


```
abstract class RecyclerView.SmoothScroller
```

<br />

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

|--------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [LinearSmoothScroller](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller) | [RecyclerView.SmoothScroller](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller) implementation which uses a [LinearInterpolator](https://developer.android.com/reference/android/view/animation/LinearInterpolator.html) until the target position becomes a child of the RecyclerView and then uses a [DecelerateInterpolator](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 [startSmoothScroll](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.LayoutManager#startSmoothScroll(androidx.recyclerview.widget.RecyclerView.SmoothScroller)).  

|                                                         See also                                                         |
|--------------------------------------------------------------------------------------------------------------------------|---|
| [LinearSmoothScroller](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller) |   |

## Summary

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

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

|                                                          ### Public functions                                                           |
|-----------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [PointF](https://developer.android.com/reference/android/graphics/PointF.html)`?`                                                       | [computeScrollVectorForPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller#computeScrollVectorForPosition(int))`(targetPosition: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Compute the scroll vector for a given target position.                                                                                                            |
| [View](https://developer.android.com/reference/android/view/View.html)`!`                                                               | [findViewByPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller#findViewByPosition(int))`(position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)`                                                                                                                                                                                                 |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                             | [getChildCount](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller#getChildCount())`()`                                                                                                                                                                                                                                                                                                     |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                             | [getChildPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller#getChildPosition(android.view.View))`(view: `[View](https://developer.android.com/reference/android/view/View.html)`!)`                                                                                                                                                                                               |
| [RecyclerView.LayoutManager](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.LayoutManager)`?` | [getLayoutManager](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller#getLayoutManager())`()`                                                                                                                                                                                                                                                                                               |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                             | [getTargetPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller#getTargetPosition())`()` Returns the adapter position of the target item                                                                                                                                                                                                                                             |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                           | ~~[instantScrollToPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller#instantScrollToPosition(int))~~`(position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` **This function is deprecated.** Use [jumpTo](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller.Action#jumpTo(int)). <br /> |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                     | [isPendingInitialRun](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller#isPendingInitialRun())`()` Returns true if SmoothScroller has been started but has not received the first animation callback yet.                                                                                                                                                                                  |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                     | [isRunning](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller#isRunning())`()`                                                                                                                                                                                                                                                                                                             |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                           | [setTargetPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller#setTargetPosition(int))`(targetPosition: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)`                                                                                                                                                                                             |

|                                 ### Protected functions                                  |
|------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)            | [normalize](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller#normalize(android.graphics.PointF))`(scrollVector: `[PointF](https://developer.android.com/reference/android/graphics/PointF.html)`)` Normalizes the vector.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)            | [onChildAttachedToWindow](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller#onChildAttachedToWindow(android.view.View))`(child: `[View](https://developer.android.com/reference/android/view/View.html)`!)`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `abstract `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [onSeekTargetStep](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller#onSeekTargetStep(int,int,androidx.recyclerview.widget.RecyclerView.State,androidx.recyclerview.widget.RecyclerView.SmoothScroller.Action))`(` ` dx: @`[Px](https://developer.android.com/reference/kotlin/androidx/annotation/Px)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` dy: @`[Px](https://developer.android.com/reference/kotlin/androidx/annotation/Px)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` state: `[RecyclerView.State](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.State)`,` ` action: `[RecyclerView.SmoothScroller.Action](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller.Action) `)` RecyclerView will call this method each time it scrolls until it can find the target position in the layout. |
| `abstract `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [onStart](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller#onStart())`()` Called when smooth scroll is started.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `abstract `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [onStop](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller#onStop())`()` Called when smooth scroller is stopped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `abstract `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [onTargetFound](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller#onTargetFound(android.view.View,androidx.recyclerview.widget.RecyclerView.State,androidx.recyclerview.widget.RecyclerView.SmoothScroller.Action))`(` ` targetView: `[View](https://developer.android.com/reference/android/view/View.html)`,` ` state: `[RecyclerView.State](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.State)`,` ` action: `[RecyclerView.SmoothScroller.Action](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller.Action) `)` Called when the target position is laid out.                                                                                                                                                                                                                                                                                                              |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)            | [stop](https://developer.android.com/reference/kotlin/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)  

```
SmoothScroller()
```  

## Public functions

### computeScrollVectorForPosition

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

```
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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | the position to which the scroller is scrolling |

|                                      Returns                                      |
|-----------------------------------------------------------------------------------|-----------------------------------------------|
| [PointF](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)  

```
fun findViewByPosition(position: Int): View!
```  

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

### getChildCount

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

```
fun getChildCount(): Int
```  

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

### getChildPosition

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

```
fun getChildPosition(view: View!): Int
```  

|                                                                           See also                                                                           |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [getChildLayoutPosition](https://developer.android.com/reference/kotlin/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)  

```
fun getLayoutManager(): RecyclerView.LayoutManager?
```  

|                                                                 Returns                                                                 |
|-----------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|
| [RecyclerView.LayoutManager](https://developer.android.com/reference/kotlin/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)  

```
fun getTargetPosition(): Int
```

Returns the adapter position of the target item  

|                                   Returns                                   |
|-----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Adapter position of the target item or [NO_POSITION](https://developer.android.com/reference/kotlin/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)  

```
fun [instantScrollToPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller#instantScrollToPosition(int))(position: Int): Unit
```
| **This function is deprecated.**   
|
Use [jumpTo](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller.Action#jumpTo(int)).  

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

### isPendingInitialRun

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

```
fun isPendingInitialRun(): Boolean
```

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

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|-------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | 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)  

```
fun isRunning(): Boolean
```  

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|--------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | True if SmoothScroller is currently active |

### setTargetPosition

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

```
fun setTargetPosition(targetPosition: Int): Unit
```  

## Protected functions

### normalize

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

```
protected fun normalize(scrollVector: PointF): Unit
```

Normalizes the vector.  

|                                           Parameters                                           |
|------------------------------------------------------------------------------------------------|------------------------------------------------------|
| `scrollVector: `[PointF](https://developer.android.com/reference/android/graphics/PointF.html) | 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 fun onChildAttachedToWindow(child: View!): Unit
```  

### onSeekTargetStep

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

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

|                                                                            Parameters                                                                            |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------|
| `dx: @`[Px](https://developer.android.com/reference/kotlin/androidx/annotation/Px)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Last scroll amount horizontally                                                             |
| `dy: @`[Px](https://developer.android.com/reference/kotlin/androidx/annotation/Px)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Last scroll amount vertically                                                               |
| `state: `[RecyclerView.State](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.State)                                    | Transient state of RecyclerView                                                             |
| `action: `[RecyclerView.SmoothScroller.Action](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller.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 fun onStart(): Unit
```

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 fun onStop(): Unit
```

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

|                                                        See also                                                        |
|------------------------------------------------------------------------------------------------------------------------|---|
| [stop](https://developer.android.com/reference/kotlin/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 fun onTargetFound(
    targetView: View,
    state: RecyclerView.State,
    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](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller.Action) to define the scroll details towards the target view.  

|                                                                           Parameters                                                                           |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------|
| `targetView: `[View](https://developer.android.com/reference/android/view/View.html)                                                                           | The view element which render the target position.                                          |
| `state: `[RecyclerView.State](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.State)                                  | Transient state of RecyclerView                                                             |
| `action: `[RecyclerView.SmoothScroller.Action](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller.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 fun stop(): Unit
```

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