# LinearSmoothScroller

# LinearSmoothScroller

Artifact:[androidx.recyclerview:recyclerview](https://developer.android.com/jetpack/androidx/releases/recyclerview)  
[View Source](https://cs.android.com/search?q=file:androidx/recyclerview/widget/LinearSmoothScroller.java+class:androidx.recyclerview.widget.LinearSmoothScroller)  
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/LinearSmoothScroller "View this page in Java")

<br />

```
class LinearSmoothScroller : RecyclerView.SmoothScroller
```

<br />

|---|---|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)                                                                          |||
| ↳ | [androidx.recyclerview.widget.RecyclerView.SmoothScroller](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller) ||
|   | ↳ | [androidx.recyclerview.widget.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.

If the[RecyclerView.LayoutManager](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.LayoutManager)you are using does not implement the[RecyclerView.SmoothScroller.ScrollVectorProvider](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller.ScrollVectorProvider)interface, then you must override the[computeScrollVectorForPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller#computeScrollVectorForPosition(int))method. All the LayoutManagers bundled with the support library implement this interface.

## Summary

|                                    ### Constants                                    |
|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [SNAP_TO_ANY](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#SNAP_TO_ANY())` = 0` Decides if the child should be snapped from start or end, depending on where it currently is in relation to its parent. |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [SNAP_TO_END](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#SNAP_TO_END())` = 1` Align child view's right or bottom with parent view's right or bottom                                                   |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [SNAP_TO_START](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#SNAP_TO_START())` = -1` Align child view's left or top with parent view's left or top                                                      |

|                                                                                                                        ### Public constructors                                                                                                                        |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [LinearSmoothScroller](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#LinearSmoothScroller(android.content.Context))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!)` |

|                            ### Public functions                             |
|-----------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [calculateDtToFit](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#calculateDtToFit(int,int,int,int,int))`(` ` viewStart: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` viewEnd: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` boxStart: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` boxEnd: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` snapPreference: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) `)` Helper method for[calculateDxToMakeVisible](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#calculateDxToMakeVisible(android.view.View,int))and[calculateDyToMakeVisible](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#calculateDyToMakeVisible(android.view.View,int)) |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [calculateDxToMakeVisible](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#calculateDxToMakeVisible(android.view.View,int))`(view: `[View](https://developer.android.com/reference/android/view/View.html)`!, snapPreference: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Calculates the horizontal scroll amount necessary to make the given view fully visible inside the RecyclerView.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [calculateDyToMakeVisible](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#calculateDyToMakeVisible(android.view.View,int))`(view: `[View](https://developer.android.com/reference/android/view/View.html)`!, snapPreference: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Calculates the vertical scroll amount necessary to make the given view fully visible inside the RecyclerView.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |

|                             ### Protected functions                             |
|---------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | [calculateSpeedPerPixel](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#calculateSpeedPerPixel(android.util.DisplayMetrics))`(displayMetrics: `[DisplayMetrics](https://developer.android.com/reference/android/util/DisplayMetrics.html)`!)` Calculates the scroll speed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)     | [calculateTimeForDeceleration](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#calculateTimeForDeceleration(int))`(dx: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Calculates the time for deceleration so that transition from LinearInterpolator to DecelerateInterpolator looks smooth.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)     | [calculateTimeForScrolling](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#calculateTimeForScrolling(int))`(dx: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Calculates the time it should take to scroll the given distance (in pixels)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)     | [getHorizontalSnapPreference](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#getHorizontalSnapPreference())`()` When scrolling towards a child view, this method defines whether we should align the left or the right edge of the child with the parent RecyclerView.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)     | [getVerticalSnapPreference](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#getVerticalSnapPreference())`()` When scrolling towards a child view, this method defines whether we should align the top or the bottom edge of the child with the parent RecyclerView.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)   | [onSeekTargetStep](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#onSeekTargetStep(int,int,androidx.recyclerview.widget.RecyclerView.State,androidx.recyclerview.widget.RecyclerView.SmoothScroller.Action))`(` ` dx: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` dy: `[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. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)   | [onStart](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#onStart())`()` Called when smooth scroll is started.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)   | [onStop](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#onStop())`()` Called when smooth scroller is stopped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)   | [onTargetFound](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#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)   | [updateActionForInterimTarget](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#updateActionForInterimTarget(androidx.recyclerview.widget.RecyclerView.SmoothScroller.Action))`(` ` action: `[RecyclerView.SmoothScroller.Action](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller.Action)`!` `)` When the target scroll position is not a child of the RecyclerView, this method calculates a direction vector towards that child and triggers a smooth scroll.                                                                                                                                                                                                                                                                                              |

|                                                ### Protected properties                                                 |
|-------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| [DecelerateInterpolator](https://developer.android.com/reference/android/view/animation/DecelerateInterpolator.html)`!` | [mDecelerateInterpolator](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#mDecelerateInterpolator()) |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                             | [mInterimTargetDx](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#mInterimTargetDx())               |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                             | [mInterimTargetDy](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#mInterimTargetDy())               |
| [LinearInterpolator](https://developer.android.com/reference/android/view/animation/LinearInterpolator.html)`!`         | [mLinearInterpolator](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#mLinearInterpolator())         |
| [PointF](https://developer.android.com/reference/android/graphics/PointF.html)`!`                                       | [mTargetVector](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#mTargetVector())                     |

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           ### Inherited functions                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From[androidx.recyclerview.widget.RecyclerView.SmoothScroller](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.SmoothScroller) |-----------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [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)                                                           | [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)`!)`                                                                                                                                                                               | | [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)`)`                                                                                                                                                                                            | | [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.                                                                                                                                                                                                                                                         | |

## Constants

### SNAP_TO_ANY

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

```
const val SNAP_TO_ANY = 0: Int
```

Decides if the child should be snapped from start or end, depending on where it currently is in relation to its parent.

For instance, if the view is virtually on the left of RecyclerView, using`SNAP_TO_ANY`is the same as using`SNAP_TO_START`  

|                                                                                   See also                                                                                   |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [calculateDtToFit](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#calculateDtToFit(int,int,int,int,int))                   |   |
| [calculateDxToMakeVisible](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#calculateDxToMakeVisible(android.view.View,int)) |   |
| [calculateDyToMakeVisible](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#calculateDyToMakeVisible(android.view.View,int)) |   |

### SNAP_TO_END

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

```
const val SNAP_TO_END = 1: Int
```

Align child view's right or bottom with parent view's right or bottom  

|                                                                                   See also                                                                                   |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [calculateDtToFit](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#calculateDtToFit(int,int,int,int,int))                   |   |
| [calculateDxToMakeVisible](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#calculateDxToMakeVisible(android.view.View,int)) |   |
| [calculateDyToMakeVisible](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#calculateDyToMakeVisible(android.view.View,int)) |   |

### SNAP_TO_START

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

```
const val SNAP_TO_START = -1: Int
```

Align child view's left or top with parent view's left or top  

|                                                                                   See also                                                                                   |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [calculateDtToFit](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#calculateDtToFit(int,int,int,int,int))                   |   |
| [calculateDxToMakeVisible](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#calculateDxToMakeVisible(android.view.View,int)) |   |
| [calculateDyToMakeVisible](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#calculateDyToMakeVisible(android.view.View,int)) |   |

## Public constructors

### LinearSmoothScroller

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

```
LinearSmoothScroller(context: Context!)
```  

## Public functions

### calculateDtToFit

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

```
fun calculateDtToFit(
    viewStart: Int,
    viewEnd: Int,
    boxStart: Int,
    boxEnd: Int,
    snapPreference: Int
): Int
```

Helper method for[calculateDxToMakeVisible](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#calculateDxToMakeVisible(android.view.View,int))and[calculateDyToMakeVisible](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#calculateDyToMakeVisible(android.view.View,int))  

### calculateDxToMakeVisible

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

```
fun calculateDxToMakeVisible(view: View!, snapPreference: Int): Int
```

Calculates the horizontal scroll amount necessary to make the given view fully visible inside the RecyclerView.  

|                                          Parameters                                           |
|-----------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `view: `[View](https://developer.android.com/reference/android/view/View.html)`!`             | The view which we want to make fully visible                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `snapPreference: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The edge which the view should snap to when entering the visible area. One of[SNAP_TO_START](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#SNAP_TO_START()),[SNAP_TO_END](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#SNAP_TO_END())or[SNAP_TO_END](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#SNAP_TO_END()) |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The vertical scroll amount necessary to make the view visible with the given snap preference. |

### calculateDyToMakeVisible

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

```
fun calculateDyToMakeVisible(view: View!, snapPreference: Int): Int
```

Calculates the vertical scroll amount necessary to make the given view fully visible inside the RecyclerView.  

|                                          Parameters                                           |
|-----------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `view: `[View](https://developer.android.com/reference/android/view/View.html)`!`             | The view which we want to make fully visible                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `snapPreference: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The edge which the view should snap to when entering the visible area. One of[SNAP_TO_START](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#SNAP_TO_START()),[SNAP_TO_END](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#SNAP_TO_END())or[SNAP_TO_ANY](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearSmoothScroller#SNAP_TO_ANY()). |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The vertical scroll amount necessary to make the view visible with the given snap preference. |

## Protected functions

### calculateSpeedPerPixel

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

```
protected fun calculateSpeedPerPixel(displayMetrics: DisplayMetrics!): Float
```

Calculates the scroll speed.

By default, LinearSmoothScroller assumes this method always returns the same value and caches the result of calling it.  

|                                                   Parameters                                                    |
|-----------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------|
| `displayMetrics: `[DisplayMetrics](https://developer.android.com/reference/android/util/DisplayMetrics.html)`!` | DisplayMetrics to be used for real dimension calculations |

|                                     Returns                                     |
|---------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | The time (in ms) it should take for each pixel. For instance, if returned value is 2 ms, it means scrolling 1000 pixels with LinearInterpolation should take 2 seconds. |

### calculateTimeForDeceleration

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

```
protected fun calculateTimeForDeceleration(dx: Int): Int
```

Calculates the time for deceleration so that transition from LinearInterpolator to DecelerateInterpolator looks smooth.  

|                                    Parameters                                     |
|-----------------------------------------------------------------------------------|--------------------|
| `dx: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Distance to scroll |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Time for DecelerateInterpolator to smoothly traverse the distance when transitioning from LinearInterpolation |

### calculateTimeForScrolling

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

```
protected fun calculateTimeForScrolling(dx: Int): Int
```

Calculates the time it should take to scroll the given distance (in pixels)  

|                                    Parameters                                     |
|-----------------------------------------------------------------------------------|-------------------------------------------|
| `dx: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Distance in pixels that we want to scroll |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|----------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Time in milliseconds |

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

### getHorizontalSnapPreference

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

```
protected fun getHorizontalSnapPreference(): Int
```

When scrolling towards a child view, this method defines whether we should align the left or the right edge of the child with the parent RecyclerView.  

|                                   Returns                                   |
|-----------------------------------------------------------------------------|-----------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | SNAP_TO_START, SNAP_TO_END or SNAP_TO_ANY; depending on the current target vector |

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

### getVerticalSnapPreference

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

```
protected fun getVerticalSnapPreference(): Int
```

When scrolling towards a child view, this method defines whether we should align the top or the bottom edge of the child with the parent RecyclerView.  

|                                   Returns                                   |
|-----------------------------------------------------------------------------|-----------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | SNAP_TO_START, SNAP_TO_END or SNAP_TO_ANY; depending on the current target vector |

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

### onSeekTargetStep

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

```
protected fun onSeekTargetStep(
    dx: Int,
    dy: 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 to define the next scroll.  

### onStart

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

```
protected fun onStart(): Unit
```

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

### onStop

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

```
protected fun onStop(): Unit
```

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

### onTargetFound

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

```
protected 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 to define the scroll details towards the target view.  

### updateActionForInterimTarget

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

```
protected fun updateActionForInterimTarget(
    action: RecyclerView.SmoothScroller.Action!
): Unit
```

When the target scroll position is not a child of the RecyclerView, this method calculates a direction vector towards that child and triggers a smooth scroll.  

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

## Protected properties

### mDecelerateInterpolator

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

```
protected val mDecelerateInterpolator: DecelerateInterpolator!
```  

### mInterimTargetDx

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

```
protected val mInterimTargetDx: Int
```  

### mInterimTargetDy

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

```
protected val mInterimTargetDy: Int
```  

### mLinearInterpolator

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

```
protected val mLinearInterpolator: LinearInterpolator!
```  

### mTargetVector

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

```
protected val mTargetVector: PointF!
```