Added in API level 9

OverScroller


open class OverScroller
kotlin.Any
   ↳ android.widget.OverScroller

This class encapsulates scrolling with the ability to overshoot the bounds of a scrolling operation. This class is a drop-in replacement for android.widget.Scroller in most cases.

Summary

Public constructors
OverScroller(context: Context!)

Creates an OverScroller with a viscous fluid scroll interpolator and flywheel.

OverScroller(context: Context!, interpolator: Interpolator!)

Creates an OverScroller with flywheel enabled.

OverScroller(context: Context!, interpolator: Interpolator!, bounceCoefficientX: Float, bounceCoefficientY: Float)

Creates an OverScroller with flywheel enabled.

OverScroller(context: Context!, interpolator: Interpolator!, bounceCoefficientX: Float, bounceCoefficientY: Float, flywheel: Boolean)

Creates an OverScroller.

Public methods
open Unit

Stops the animation.

open Boolean

Call this when you want to know the new location.

open Unit
fling(startX: Int, startY: Int, velocityX: Int, velocityY: Int, minX: Int, maxX: Int, minY: Int, maxY: Int)

open Unit
fling(startX: Int, startY: Int, velocityX: Int, velocityY: Int, minX: Int, maxX: Int, minY: Int, maxY: Int, overX: Int, overY: Int)

Start scrolling based on a fling gesture.

Unit

Force the finished field to a particular value.

open Float

Returns the absolute value of the current velocity.

Int

Returns the current X offset in the scroll.

Int

Returns the current Y offset in the scroll.

Int

Returns where the scroll will end.

Int

Returns where the scroll will end.

Int

Returns the start X offset in the scroll.

Int

Returns the start Y offset in the scroll.

Boolean

Returns whether the scroller has finished scrolling.

open Boolean

Returns whether the current Scroller is currently returning to a valid position.

open Unit
notifyHorizontalEdgeReached(startX: Int, finalX: Int, overX: Int)

Notify the scroller that we've reached a horizontal boundary.

open Unit
notifyVerticalEdgeReached(startY: Int, finalY: Int, overY: Int)

Notify the scroller that we've reached a vertical boundary.

Unit
setFriction(friction: Float)

The amount of friction applied to flings.

open Boolean
springBack(startX: Int, startY: Int, minX: Int, maxX: Int, minY: Int, maxY: Int)

Call this when you want to 'spring back' into a valid coordinate range.

open Unit
startScroll(startX: Int, startY: Int, dx: Int, dy: Int)

Start scrolling by providing a starting point and the distance to travel.

open Unit
startScroll(startX: Int, startY: Int, dx: Int, dy: Int, duration: Int)

Start scrolling by providing a starting point and the distance to travel.

Public constructors

OverScroller

Added in API level 9
OverScroller(context: Context!)

Creates an OverScroller with a viscous fluid scroll interpolator and flywheel.

Parameters
context Context!:

OverScroller

Added in API level 9
OverScroller(
    context: Context!,
    interpolator: Interpolator!)

Creates an OverScroller with flywheel enabled.

Parameters
context Context!: The context of this application.
interpolator Interpolator!: The scroll interpolator. If null, a default (viscous) interpolator will be used.

OverScroller

Added in API level 9
OverScroller(
    context: Context!,
    interpolator: Interpolator!,
    bounceCoefficientX: Float,
    bounceCoefficientY: Float)

Deprecated: Use OverScroller(android.content.Context,android.view.animation.Interpolator) instead.

Creates an OverScroller with flywheel enabled.

Parameters
context Context!: The context of this application.
interpolator Interpolator!: The scroll interpolator. If null, a default (viscous) interpolator will be used.
bounceCoefficientX Float: A value between 0 and 1 that will determine the proportion of the velocity which is preserved in the bounce when the horizontal edge is reached. A null value means no bounce. This behavior is no longer supported and this coefficient has no effect.
bounceCoefficientY Float: Same as bounceCoefficientX but for the vertical direction. This behavior is no longer supported and this coefficient has no effect.

OverScroller

Added in API level 11
OverScroller(
    context: Context!,
    interpolator: Interpolator!,
    bounceCoefficientX: Float,
    bounceCoefficientY: Float,
    flywheel: Boolean)

Deprecated: Use OverScroller(android.content.Context,android.view.animation.Interpolator) instead.

Creates an OverScroller.

Parameters
context Context!: The context of this application.
interpolator Interpolator!: The scroll interpolator. If null, a default (viscous) interpolator will be used.
bounceCoefficientX Float: A value between 0 and 1 that will determine the proportion of the velocity which is preserved in the bounce when the horizontal edge is reached. A null value means no bounce. This behavior is no longer supported and this coefficient has no effect.
bounceCoefficientY Float: Same as bounceCoefficientX but for the vertical direction. This behavior is no longer supported and this coefficient has no effect.
flywheel Boolean: If true, successive fling motions will keep on increasing scroll speed.

Public methods

abortAnimation

Added in API level 9
open fun abortAnimation(): Unit

Stops the animation. Contrary to forceFinished(boolean), aborting the animating causes the scroller to move to the final x and y positions.

computeScrollOffset

Added in API level 9
open fun computeScrollOffset(): Boolean

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

fling

Added in API level 9
open fun fling(
    startX: Int,
    startY: Int,
    velocityX: Int,
    velocityY: Int,
    minX: Int,
    maxX: Int,
    minY: Int,
    maxY: Int
): Unit

fling

Added in API level 9
open fun fling(
    startX: Int,
    startY: Int,
    velocityX: Int,
    velocityY: Int,
    minX: Int,
    maxX: Int,
    minY: Int,
    maxY: Int,
    overX: Int,
    overY: Int
): Unit

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

Parameters
startX Int: Starting point of the scroll (X)
startY Int: Starting point of the scroll (Y)
velocityX Int: Initial velocity of the fling (X) measured in pixels per second.
velocityY Int: Initial velocity of the fling (Y) measured in pixels per second
minX Int: Minimum X value. The scroller will not scroll past this point unless overX > 0. If overfling is allowed, it will use minX as a springback boundary.
maxX Int: Maximum X value. The scroller will not scroll past this point unless overX > 0. If overfling is allowed, it will use maxX as a springback boundary.
minY Int: Minimum Y value. The scroller will not scroll past this point unless overY > 0. If overfling is allowed, it will use minY as a springback boundary.
maxY Int: Maximum Y value. The scroller will not scroll past this point unless overY > 0. If overfling is allowed, it will use maxY as a springback boundary.
overX Int: Overfling range. If > 0, horizontal overfling in either direction will be possible.
overY Int: Overfling range. If > 0, vertical overfling in either direction will be possible.

forceFinished

Added in API level 9
fun forceFinished(finished: Boolean): Unit

Force the finished field to a particular value. Contrary to abortAnimation(), forcing the animation to finished does NOT cause the scroller to move to the final x and y position.

Parameters
finished Boolean: The new finished value.

getCurrVelocity

Added in API level 14
open fun getCurrVelocity(): Float

Returns the absolute value of the current velocity.

Return
Float The original velocity less the deceleration, norm of the X and Y velocity vector.

getCurrX

Added in API level 9
fun getCurrX(): Int

Returns the current X offset in the scroll.

Return
Int The new X offset as an absolute distance from the origin.

getCurrY

Added in API level 9
fun getCurrY(): Int

Returns the current Y offset in the scroll.

Return
Int The new Y offset as an absolute distance from the origin.

getFinalX

Added in API level 9
fun getFinalX(): Int

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

Return
Int The final X offset as an absolute distance from the origin.

getFinalY

Added in API level 9
fun getFinalY(): Int

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

Return
Int The final Y offset as an absolute distance from the origin.

getStartX

Added in API level 9
fun getStartX(): Int

Returns the start X offset in the scroll.

Return
Int The start X offset as an absolute distance from the origin.

getStartY

Added in API level 9
fun getStartY(): Int

Returns the start Y offset in the scroll.

Return
Int The start Y offset as an absolute distance from the origin.

isFinished

Added in API level 9
fun isFinished(): Boolean

Returns whether the scroller has finished scrolling.

Return
Boolean True if the scroller has finished scrolling, false otherwise.

isOverScrolled

Added in API level 9
open fun isOverScrolled(): Boolean

Returns whether the current Scroller is currently returning to a valid position. Valid bounds were provided by the fling(int,int,int,int,int,int,int,int,int,int) method. One should check this value before calling startScroll(int,int,int,int) as the interpolation currently in progress to restore a valid position will then be stopped. The caller has to take into account the fact that the started scroll will start from an overscrolled position.

Return
Boolean true when the current position is overscrolled and in the process of interpolating back to a valid value.

notifyHorizontalEdgeReached

Added in API level 9
open fun notifyHorizontalEdgeReached(
    startX: Int,
    finalX: Int,
    overX: Int
): Unit

Notify the scroller that we've reached a horizontal boundary. Normally the information to handle this will already be known when the animation is started, such as in a call to one of the fling functions. However there are cases where this cannot be known in advance. This function will transition the current motion and animate from startX to finalX as appropriate.

Parameters
startX Int: Starting/current X position
finalX Int: Desired final X position
overX Int: Magnitude of overscroll allowed. This should be the maximum desired distance from finalX. Absolute value - must be positive.

notifyVerticalEdgeReached

Added in API level 9
open fun notifyVerticalEdgeReached(
    startY: Int,
    finalY: Int,
    overY: Int
): Unit

Notify the scroller that we've reached a vertical boundary. Normally the information to handle this will already be known when the animation is started, such as in a call to one of the fling functions. However there are cases where this cannot be known in advance. This function will animate a parabolic motion from startY to finalY.

Parameters
startY Int: Starting/current Y position
finalY Int: Desired final Y position
overY Int: Magnitude of overscroll allowed. This should be the maximum desired distance from finalY. Absolute value - must be positive.

setFriction

Added in API level 11
fun setFriction(friction: Float): Unit

The amount of friction applied to flings. The default value is ViewConfiguration#getScrollFriction.

Parameters
friction Float: A scalar dimension-less value representing the coefficient of friction.

springBack

Added in API level 9
open fun springBack(
    startX: Int,
    startY: Int,
    minX: Int,
    maxX: Int,
    minY: Int,
    maxY: Int
): Boolean

Call this when you want to 'spring back' into a valid coordinate range.

Parameters
startX Int: Starting X coordinate
startY Int: Starting Y coordinate
minX Int: Minimum valid X value
maxX Int: Maximum valid X value
minY Int: Minimum valid Y value
maxY Int: Minimum valid Y value
Return
Boolean true if a springback was initiated, false if startX and startY were already within the valid range.

startScroll

Added in API level 9
open fun startScroll(
    startX: Int,
    startY: Int,
    dx: Int,
    dy: Int
): Unit

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.

Parameters
startX Int: Starting horizontal scroll offset in pixels. Positive numbers will scroll the content to the left.
startY Int: Starting vertical scroll offset in pixels. Positive numbers will scroll the content up.
dx Int: Horizontal distance to travel. Positive numbers will scroll the content to the left.
dy Int: Vertical distance to travel. Positive numbers will scroll the content up.

startScroll

Added in API level 9
open fun startScroll(
    startX: Int,
    startY: Int,
    dx: Int,
    dy: Int,
    duration: Int
): Unit

Start scrolling by providing a starting point and the distance to travel.

Parameters
startX Int: Starting horizontal scroll offset in pixels. Positive numbers will scroll the content to the left.
startY Int: Starting vertical scroll offset in pixels. Positive numbers will scroll the content up.
dx Int: Horizontal distance to travel. Positive numbers will scroll the content to the left.
dy Int: Vertical distance to travel. Positive numbers will scroll the content up.
duration Int: Duration of the scroll in milliseconds.