Android 12 Developer Preview is here! Try it out, and give us your feedback!

AutoScrollHelper

abstract class AutoScrollHelper : OnTouchListener
kotlin.Any
   ↳ androidx.core.widget.AutoScrollHelper

AutoScrollHelper is a utility class for adding automatic edge-triggered scrolling to Views.

Note: Implementing classes are responsible for overriding the scrollTargetBy, canTargetScrollHorizontally, and canTargetScrollVertically methods. See ListViewAutoScrollHelper for a android.widget.ListView -specific implementation.

Activation

Automatic scrolling starts when the user touches within an activation area. By default, activation areas are defined as the top, left, right, and bottom 20% of the host view's total area. Touching within the top activation area scrolls up, left scrolls to the left, and so on.

As the user touches closer to the extreme edge of the activation area, scrolling accelerates up to a maximum velocity. When using the default edge type, EDGE_TYPE_INSIDE_EXTEND, moving outside of the view bounds will scroll at the maximum velocity.

The following activation properties may be configured:

Scrolling

When automatic scrolling is active, the helper will repeatedly call scrollTargetBy to apply new scrolling offsets.

The following scrolling properties may be configured:

  • Acceleration ramp-up duration, see setRampUpDuration. Default value is 500 milliseconds.
  • Acceleration ramp-down duration, see setRampDownDuration. Default value is 500 milliseconds.
  • Target velocity relative to view size, see setRelativeVelocity. Default value is 100% per second for both vertical and horizontal.
  • Minimum velocity used to constrain relative velocity, see setMinimumVelocity. When set, scrolling will accelerate to the larger of either this value or the relative target value. Default value is approximately 5 centimeters or 315 dips per second.
  • Maximum velocity used to constrain relative velocity, see setMaximumVelocity. Default value is approximately 25 centimeters or 1575 dips per second.

Summary

Constants
static Int

Edge type that specifies an activation area starting at the view bounds and extending inward.

static Int

Edge type that specifies an activation area starting at the view bounds and extending inward.

static Int

Edge type that specifies an activation area starting at the view bounds and extending outward.

static Float

Constant passed to setMaximumEdges, setMaximumVelocity, or setMinimumVelocity.

static Float

Constant passed to setMaximumEdges, or setMaximumVelocity, or setMinimumVelocity.

static Float

Constant passed to setRelativeEdges or setRelativeVelocity.

Public constructors
<init>(@NonNull target: View)

Creates a new helper for scrolling the specified target view.

Public methods
abstract Boolean

Override this method to return whether the target view can be scrolled horizontally in a certain direction.

abstract Boolean

Override this method to return whether the target view can be scrolled vertically in a certain direction.

open Boolean

open Boolean

Indicates whether the scroll helper handles touch events exclusively during scrolling.

open Boolean
onTouch(v: View!, event: MotionEvent!)

Handles touch events by activating automatic scrolling, adjusting scroll velocity, or stopping.

abstract Unit
scrollTargetBy(deltaX: Int, deltaY: Int)

Override this method to scroll the target view by the specified number of pixels.

open AutoScrollHelper
setActivationDelay(delayMillis: Int)

Sets the delay after entering an activation edge before activation of auto-scrolling.

open AutoScrollHelper

Sets the activation edge type, one of:

  • EDGE_TYPE_INSIDE for edges that respond to touches inside the bounds of the host view. If touch moves outside the bounds, scrolling will stop.
  • EDGE_TYPE_INSIDE_EXTEND for inside edges that continued to scroll when touch moves outside the bounds of the host view.
  • EDGE_TYPE_OUTSIDE for edges that only respond to touches that move outside the bounds of the host view.

open AutoScrollHelper!
setEnabled(enabled: Boolean)

Sets whether the scroll helper is enabled and should respond to touch events.

open AutoScrollHelper!
setExclusive(exclusive: Boolean)

Enables or disables exclusive handling of touch events during scrolling.

open AutoScrollHelper
setMaximumEdges(horizontalMax: Float, verticalMax: Float)

Sets the absolute maximum edge size.

open AutoScrollHelper
setMaximumVelocity(horizontalMax: Float, verticalMax: Float)

Sets the absolute maximum scrolling velocity.

open AutoScrollHelper
setMinimumVelocity(horizontalMin: Float, verticalMin: Float)

Sets the absolute minimum scrolling velocity.