# Scroller

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/android/widget/Scroller#pubctors)\|[Methods](https://developer.android.com/reference/android/widget/Scroller#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/widget/Scroller#inhmethods)  

# Scroller

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/widget/Scroller "View this page in Kotlin")\|Java

`
public


class
Scroller
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|-------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.widget.Scroller |

<br />

*** ** * ** ***

<br />

This class encapsulates scrolling. You can use scrollers ([Scroller](https://developer.android.com/reference/android/widget/Scroller)or[OverScroller](https://developer.android.com/reference/android/widget/OverScroller)) to collect the data you need to produce a scrolling animation---for example, in response to a fling gesture. Scrollers track scroll offsets for you over time, but they don't automatically apply those positions to your view. It's your responsibility to get and apply new coordinates at a rate that will make the scrolling animation look smooth.

Here is a simple example:  

```
 private Scroller mScroller = new Scroller(context);
 ...
 public void zoomIn() {
     // Revert any animation currently in progress
     mScroller.forceFinished(true);
     // Start scrolling by providing a starting point and
     // the distance to travel
     mScroller.startScroll(0, 0, 100, 0);
     // Invalidate to request a redraw
     invalidate();
 }
```

To track the changing positions of the x/y coordinates, use[computeScrollOffset()](https://developer.android.com/reference/android/widget/Scroller#computeScrollOffset()). The method returns a boolean to indicate whether the scroller is finished. If it isn't, it means that a fling or programmatic pan operation is still in progress. You can use this method to find the current offsets of the x and y coordinates, for example:  

```
if (mScroller.computeScrollOffset()) {
     // Get current x and y positions
     int currX = mScroller.getCurrX();
     int currY = mScroller.getCurrY();
    ...
 }
```

<br />

## Summary

|                                                                                                                                                                                                             ### Public constructors                                                                                                                                                                                                             ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[Scroller](https://developer.android.com/reference/android/widget/Scroller#Scroller(android.content.Context))`(`[Context](https://developer.android.com/reference/android/content/Context)` context) ` Create a Scroller with the default duration and interpolator.                                                                                                                                                                      |
| ` `[Scroller](https://developer.android.com/reference/android/widget/Scroller#Scroller(android.content.Context,%20android.view.animation.Interpolator))`(`[Context](https://developer.android.com/reference/android/content/Context)` context, `[Interpolator](https://developer.android.com/reference/android/view/animation/Interpolator)` interpolator) ` Create a Scroller with the specified interpolator.                              |
| ` `[Scroller](https://developer.android.com/reference/android/widget/Scroller#Scroller(android.content.Context,%20android.view.animation.Interpolator,%20boolean))`(`[Context](https://developer.android.com/reference/android/content/Context)` context, `[Interpolator](https://developer.android.com/reference/android/view/animation/Interpolator)` interpolator, boolean flywheel) ` Create a Scroller with the specified interpolator. |

|                                                                                                                                                ### Public methods                                                                                                                                                ||
|------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`          | ` `[abortAnimation](https://developer.android.com/reference/android/widget/Scroller#abortAnimation())`() ` Stops the animation.                                                                                                                                                                |
| ` boolean`       | ` `[computeScrollOffset](https://developer.android.com/reference/android/widget/Scroller#computeScrollOffset())`() ` Call this when you want to know the new location.                                                                                                                         |
| ` void`          | ` `[extendDuration](https://developer.android.com/reference/android/widget/Scroller#extendDuration(int))`(int extend) ` Extend the scroll animation.                                                                                                                                           |
| ` void`          | ` `[fling](https://developer.android.com/reference/android/widget/Scroller#fling(int,%20int,%20int,%20int,%20int,%20int,%20int,%20int))`(int startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY, int maxY) ` Start scrolling based on a fling gesture.             |
| ` final void`    | ` `[forceFinished](https://developer.android.com/reference/android/widget/Scroller#forceFinished(boolean))`(boolean finished) ` Force the finished field to a particular value.                                                                                                                |
| ` float`         | ` `[getCurrVelocity](https://developer.android.com/reference/android/widget/Scroller#getCurrVelocity())`() ` Returns the current velocity.                                                                                                                                                     |
| ` final int`     | ` `[getCurrX](https://developer.android.com/reference/android/widget/Scroller#getCurrX())`() ` Returns the current X offset in the scroll.                                                                                                                                                     |
| ` final int`     | ` `[getCurrY](https://developer.android.com/reference/android/widget/Scroller#getCurrY())`() ` Returns the current Y offset in the scroll.                                                                                                                                                     |
| ` final int`     | ` `[getDuration](https://developer.android.com/reference/android/widget/Scroller#getDuration())`() ` Returns how long the scroll event will take, in milliseconds.                                                                                                                             |
| ` final int`     | ` `[getFinalX](https://developer.android.com/reference/android/widget/Scroller#getFinalX())`() ` Returns where the scroll will end.                                                                                                                                                            |
| ` final int`     | ` `[getFinalY](https://developer.android.com/reference/android/widget/Scroller#getFinalY())`() ` Returns where the scroll will end.                                                                                                                                                            |
| ` final int`     | ` `[getStartX](https://developer.android.com/reference/android/widget/Scroller#getStartX())`() ` Returns the start X offset in the scroll.                                                                                                                                                     |
| ` final int`     | ` `[getStartY](https://developer.android.com/reference/android/widget/Scroller#getStartY())`() ` Returns the start Y offset in the scroll.                                                                                                                                                     |
| ` final boolean` | ` `[isFinished](https://developer.android.com/reference/android/widget/Scroller#isFinished())`() ` Returns whether the scroller has finished scrolling.                                                                                                                                        |
| ` void`          | ` `[setFinalX](https://developer.android.com/reference/android/widget/Scroller#setFinalX(int))`(int newX) ` Sets the final position (X) for this scroller.                                                                                                                                     |
| ` void`          | ` `[setFinalY](https://developer.android.com/reference/android/widget/Scroller#setFinalY(int))`(int newY) ` Sets the final position (Y) for this scroller.                                                                                                                                     |
| ` final void`    | ` `[setFriction](https://developer.android.com/reference/android/widget/Scroller#setFriction(float))`(float friction) ` The amount of friction applied to flings.                                                                                                                              |
| ` void`          | ` `[startScroll](https://developer.android.com/reference/android/widget/Scroller#startScroll(int,%20int,%20int,%20int,%20int))`(int startX, int startY, int dx, int dy, int duration) ` Start scrolling by providing a starting point, the distance to travel, and the duration of the scroll. |
| ` void`          | ` `[startScroll](https://developer.android.com/reference/android/widget/Scroller#startScroll(int,%20int,%20int,%20int))`(int startX, int startY, int dx, int dy) ` Start scrolling by providing a starting point and the distance to travel.                                                   |
| ` int`           | ` `[timePassed](https://developer.android.com/reference/android/widget/Scroller#timePassed())`() ` Returns the time elapsed since the beginning of the scrolling.                                                                                                                              |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public constructors

### Scroller

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Scroller (Context context)
```

Create a Scroller with the default duration and interpolator.

<br />

|         Parameters          ||
|-----------|------------------|
| `context` | `Context` <br /> |

### Scroller

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Scroller (Context context, 
                Interpolator interpolator)
```

Create a Scroller with the specified interpolator. If the interpolator is null, the default (viscous) interpolator will be used. "Flywheel" behavior will be in effect for apps targeting Honeycomb or newer.

<br />

|              Parameters               ||
|----------------|-----------------------|
| `context`      | `Context` <br />      |
| `interpolator` | `Interpolator` <br /> |

### Scroller

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Scroller (Context context, 
                Interpolator interpolator, 
                boolean flywheel)
```

Create a Scroller with the specified interpolator. If the interpolator is null, the default (viscous) interpolator will be used. Specify whether or not to support progressive "flywheel" behavior in flinging.

<br />

|              Parameters               ||
|----------------|-----------------------|
| `context`      | `Context` <br />      |
| `interpolator` | `Interpolator` <br /> |
| `flywheel`     | `boolean` <br />      |

## Public methods

### abortAnimation

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void abortAnimation ()
```

Stops the animation. Contrary to[forceFinished(boolean)](https://developer.android.com/reference/android/widget/Scroller#forceFinished(boolean)), aborting the animating cause the scroller to move to the final x and y position

<br />

**See also:**

- [forceFinished(boolean)](https://developer.android.com/reference/android/widget/Scroller#forceFinished(boolean))  

### computeScrollOffset

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean computeScrollOffset ()
```

Call this when you want to know the new location. If it returns true, the animation is not yet finished.

<br />

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

### extendDuration

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void extendDuration (int extend)
```

Extend the scroll animation. This allows a running animation to scroll further and longer, when used with[setFinalX(int)](https://developer.android.com/reference/android/widget/Scroller#setFinalX(int))or[setFinalY(int)](https://developer.android.com/reference/android/widget/Scroller#setFinalY(int)).

<br />

|                             Parameters                             ||
|----------|----------------------------------------------------------|
| `extend` | `int`: Additional time to scroll in milliseconds. <br /> |

**See also:**

- [setFinalX(int)](https://developer.android.com/reference/android/widget/Scroller#setFinalX(int))
- [setFinalY(int)](https://developer.android.com/reference/android/widget/Scroller#setFinalY(int))  

### fling

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void fling (int startX, 
                int startY, 
                int velocityX, 
                int velocityY, 
                int minX, 
                int maxX, 
                int minY, 
                int maxY)
```

Start scrolling based on a fling gesture. The distance travelled will depend on the initial velocity of the fling.

<br />

|                                         Parameters                                          ||
|-------------|--------------------------------------------------------------------------------|
| `startX`    | `int`: Starting point of the scroll (X) <br />                                 |
| `startY`    | `int`: Starting point of the scroll (Y) <br />                                 |
| `velocityX` | `int`: Initial velocity of the fling (X) measured in pixels per second. <br /> |
| `velocityY` | `int`: Initial velocity of the fling (Y) measured in pixels per second <br />  |
| `minX`      | `int`: Minimum X value. The scroller will not scroll past this point. <br />   |
| `maxX`      | `int`: Maximum X value. The scroller will not scroll past this point. <br />   |
| `minY`      | `int`: Minimum Y value. The scroller will not scroll past this point. <br />   |
| `maxY`      | `int`: Maximum Y value. The scroller will not scroll past this point. <br />   |

### forceFinished

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final void forceFinished (boolean finished)
```

Force the finished field to a particular value.

<br />

|                      Parameters                       ||
|------------|-------------------------------------------|
| `finished` | `boolean`: The new finished value. <br /> |

### getCurrVelocity

Added in[API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public float getCurrVelocity ()
```

Returns the current velocity.

<br />

|                                       Returns                                        ||
|---------|-----------------------------------------------------------------------------|
| `float` | The original velocity less the deceleration. Result may be negative. <br /> |

### getCurrX

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final int getCurrX ()
```

Returns the current X offset in the scroll.

<br />

|                                 Returns                                 ||
|-------|------------------------------------------------------------------|
| `int` | The new X offset as an absolute distance from the origin. <br /> |

### getCurrY

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final int getCurrY ()
```

Returns the current Y offset in the scroll.

<br />

|                                 Returns                                 ||
|-------|------------------------------------------------------------------|
| `int` | The new Y offset as an absolute distance from the origin. <br /> |

### getDuration

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final int getDuration ()
```

Returns how long the scroll event will take, in milliseconds.

<br />

|                          Returns                          ||
|-------|----------------------------------------------------|
| `int` | The duration of the scroll in milliseconds. <br /> |

### getFinalX

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final int getFinalX ()
```

Returns where the scroll will end. Valid only for "fling" scrolls.

<br />

|                                  Returns                                  ||
|-------|--------------------------------------------------------------------|
| `int` | The final X offset as an absolute distance from the origin. <br /> |

### getFinalY

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final int getFinalY ()
```

Returns where the scroll will end. Valid only for "fling" scrolls.

<br />

|                                  Returns                                  ||
|-------|--------------------------------------------------------------------|
| `int` | The final Y offset as an absolute distance from the origin. <br /> |

### getStartX

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final int getStartX ()
```

Returns the start X offset in the scroll.

<br />

|                                  Returns                                  ||
|-------|--------------------------------------------------------------------|
| `int` | The start X offset as an absolute distance from the origin. <br /> |

### getStartY

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final int getStartY ()
```

Returns the start Y offset in the scroll.

<br />

|                                  Returns                                  ||
|-------|--------------------------------------------------------------------|
| `int` | The start Y offset as an absolute distance from the origin. <br /> |

### isFinished

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final boolean isFinished ()
```

Returns whether the scroller has finished scrolling.

<br />

|                                     Returns                                     ||
|-----------|----------------------------------------------------------------------|
| `boolean` | True if the scroller has finished scrolling, false otherwise. <br /> |

### setFinalX

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setFinalX (int newX)
```

Sets the final position (X) for this scroller.

<br />

|                                   Parameters                                    ||
|--------|-------------------------------------------------------------------------|
| `newX` | `int`: The new X offset as an absolute distance from the origin. <br /> |

**See also:**

- [extendDuration(int)](https://developer.android.com/reference/android/widget/Scroller#extendDuration(int))
- [setFinalY(int)](https://developer.android.com/reference/android/widget/Scroller#setFinalY(int))  

### setFinalY

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setFinalY (int newY)
```

Sets the final position (Y) for this scroller.

<br />

|                                   Parameters                                    ||
|--------|-------------------------------------------------------------------------|
| `newY` | `int`: The new Y offset as an absolute distance from the origin. <br /> |

**See also:**

- [extendDuration(int)](https://developer.android.com/reference/android/widget/Scroller#extendDuration(int))
- [setFinalX(int)](https://developer.android.com/reference/android/widget/Scroller#setFinalX(int))  

### setFriction

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final void setFriction (float friction)
```

The amount of friction applied to flings. The default value is[ViewConfiguration.getScrollFriction](https://developer.android.com/reference/android/view/ViewConfiguration#getScrollFriction()).

<br />

|                                             Parameters                                              ||
|------------|-----------------------------------------------------------------------------------------|
| `friction` | `float`: A scalar dimension-less value representing the coefficient of friction. <br /> |

### startScroll

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void startScroll (int startX, 
                int startY, 
                int dx, 
                int dy, 
                int duration)
```

Start scrolling by providing a starting point, the distance to travel, and the duration of the scroll.

<br />

|                                                          Parameters                                                          ||
|------------|------------------------------------------------------------------------------------------------------------------|
| `startX`   | `int`: Starting horizontal scroll offset in pixels. Positive numbers will scroll the content to the left. <br /> |
| `startY`   | `int`: Starting vertical scroll offset in pixels. Positive numbers will scroll the content up. <br />            |
| `dx`       | `int`: Horizontal distance to travel. Positive numbers will scroll the content to the left. <br />               |
| `dy`       | `int`: Vertical distance to travel. Positive numbers will scroll the content up. <br />                          |
| `duration` | `int`: Duration of the scroll in milliseconds. <br />                                                            |

### startScroll

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void startScroll (int startX, 
                int startY, 
                int dx, 
                int dy)
```

Start scrolling by providing a starting point and the distance to travel. The scroll will use the default value of 250 milliseconds for the duration.

<br />

|                                                         Parameters                                                         ||
|----------|------------------------------------------------------------------------------------------------------------------|
| `startX` | `int`: Starting horizontal scroll offset in pixels. Positive numbers will scroll the content to the left. <br /> |
| `startY` | `int`: Starting vertical scroll offset in pixels. Positive numbers will scroll the content up. <br />            |
| `dx`     | `int`: Horizontal distance to travel. Positive numbers will scroll the content to the left. <br />               |
| `dy`     | `int`: Vertical distance to travel. Positive numbers will scroll the content up. <br />                          |

### timePassed

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int timePassed ()
```

Returns the time elapsed since the beginning of the scrolling.

<br />

|                     Returns                     ||
|-------|------------------------------------------|
| `int` | The elapsed time in milliseconds. <br /> |