ScrollerCompat

Added in 1.1.0
Deprecated in 1.1.0

class ScrollerCompat


Provides access to new Scroller APIs when available.

This class provides a platform version-independent mechanism for obeying the current device's preferred scroll physics and fling behavior. It offers a subset of the APIs from Scroller or OverScroller.

Summary

Public functions

Unit

This function is deprecated.

Use abortAnimation directly.

Boolean

This function is deprecated.

Use computeScrollOffset directly.

java-static ScrollerCompat!
create(context: Context!)

This function is deprecated.

Use OverScroller constructor directly.

java-static ScrollerCompat!
create(context: Context!, interpolator: Interpolator!)

This function is deprecated.

Use OverScroller constructor directly.

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

This function is deprecated.

Use fling directly.

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

This function is deprecated.

Use fling directly.

Float

This function is deprecated.

Use getCurrVelocity directly.

Int

This function is deprecated.

Use getCurrX directly.

Int

This function is deprecated.

Use getCurrY directly.

Int

This function is deprecated.

Use getFinalX directly.

Int

This function is deprecated.

Use getFinalY directly.

Boolean

This function is deprecated.

Use isFinished directly.

Boolean

This function is deprecated.

Use isOverScrolled directly.

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

This function is deprecated.

Use notifyHorizontalEdgeReached directly.

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

This function is deprecated.

Use notifyVerticalEdgeReached directly.

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

This function is deprecated.

Use springBack directly.

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

This function is deprecated.

Use getCurrX directly.

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

This function is deprecated.

Use startScroll directly.

Public functions

abortAnimation

Added in 1.1.0
Deprecated in 1.1.0
fun abortAnimation(): Unit

Stops the animation. Aborting the animation causes the scroller to move to the final x and y position.

computeScrollOffset

Added in 1.1.0
Deprecated in 1.1.0
fun computeScrollOffset(): Boolean

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

create

Added in 1.1.0
Deprecated in 1.1.0
java-static fun create(context: Context!): ScrollerCompat!

create

Added in 1.1.0
Deprecated in 1.1.0
java-static fun create(context: Context!, interpolator: Interpolator!): ScrollerCompat!

fling

Added in 1.1.0
Deprecated in 1.1.0
fun fling(
    startX: Int,
    startY: Int,
    velocityX: Int,
    velocityY: Int,
    minX: Int,
    maxX: Int,
    minY: Int,
    maxY: Int
): Unit

Start scrolling based on a fling gesture. The distance travelled 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.

maxX: Int

Maximum X value. The scroller will not scroll past this point.

minY: Int

Minimum Y value. The scroller will not scroll past this point.

maxY: Int

Maximum Y value. The scroller will not scroll past this point.

fling

Added in 1.1.0
Deprecated in 1.1.0
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 travelled 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.

maxX: Int

Maximum X value. The scroller will not scroll past this point.

minY: Int

Minimum Y value. The scroller will not scroll past this point.

maxY: Int

Maximum Y value. The scroller will not scroll past this point.

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.

getCurrVelocity

Added in 1.1.0
Deprecated in 1.1.0
fun getCurrVelocity(): Float

Returns the current velocity on platform versions that support it.

This method should only be used as input for nonessential visual effects such as EdgeEffectCompat.

Returns
Float

The original velocity less the deceleration. Result may be negative.

getCurrX

Added in 1.1.0
Deprecated in 1.1.0
fun getCurrX(): Int

Returns the current X offset in the scroll.

Returns
Int

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

getCurrY

Added in 1.1.0
Deprecated in 1.1.0
fun getCurrY(): Int

Returns the current Y offset in the scroll.

Returns
Int

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

getFinalX

Added in 1.1.0
Deprecated in 1.1.0
fun getFinalX(): Int
Returns
Int

The final X position for the scroll in progress, if known.

getFinalY

Added in 1.1.0
Deprecated in 1.1.0
fun getFinalY(): Int
Returns
Int

The final Y position for the scroll in progress, if known.

isFinished

Added in 1.1.0
Deprecated in 1.1.0
fun isFinished(): Boolean

Returns whether the scroller has finished scrolling.

Returns
Boolean

True if the scroller has finished scrolling, false otherwise.

isOverScrolled

Added in 1.1.0
Deprecated in 1.1.0
fun isOverScrolled(): Boolean

Returns whether the current Scroller is currently returning to a valid position. Valid bounds were provided by the fling method. One should check this value before calling startScroll 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.

Returns
Boolean

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

notifyHorizontalEdgeReached

Added in 1.1.0
Deprecated in 1.1.0
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 1.1.0
Deprecated in 1.1.0
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.

springBack

Added in 1.1.0
Deprecated in 1.1.0
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

Maximum valid Y value

Returns
Boolean

true if a springback was initiated, false if startX and startY were already within the valid range.

startScroll

Added in 1.1.0
Deprecated in 1.1.0
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 1.1.0
Deprecated in 1.1.0
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.