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.

Inheritors

Constructors

Link copied to clipboard
constructor(@NonNull target: View)
Creates a new helper for scrolling the specified target view.

Properties

Link copied to clipboard
Edge type that specifies an activation area starting at the view bounds and extending inward.
Link copied to clipboard
Edge type that specifies an activation area starting at the view bounds and extending inward.
Link copied to clipboard
Edge type that specifies an activation area starting at the view bounds and extending outward.
Link copied to clipboard
val NO_MAX: Float = 3.4028235E38f
Link copied to clipboard
val NO_MIN: Float = 0.0f
Link copied to clipboard

Functions

Link copied to clipboard
abstract fun canTargetScrollHorizontally(direction: Int): Boolean
Override this method to return whether the target view can be scrolled horizontally in a certain direction.
Link copied to clipboard
abstract fun canTargetScrollVertically(direction: Int): Boolean
Override this method to return whether the target view can be scrolled vertically in a certain direction.
Link copied to clipboard
open fun isEnabled(): Boolean
Link copied to clipboard
open fun isExclusive(): Boolean
Indicates whether the scroll helper handles touch events exclusively during scrolling.
Link copied to clipboard
open fun onTouch(v: View, event: MotionEvent): Boolean
Handles touch events by activating automatic scrolling, adjusting scroll velocity, or stopping.
Link copied to clipboard
abstract fun scrollTargetBy(deltaX: Int, deltaY: Int)
Override this method to scroll the target view by the specified number of pixels.
Link copied to clipboard
Sets the delay after entering an activation edge before activation of auto-scrolling.
Link copied to clipboard
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.
Link copied to clipboard
open fun setEnabled(enabled: Boolean): AutoScrollHelper
Sets whether the scroll helper is enabled and should respond to touch events.
Link copied to clipboard
open fun setExclusive(exclusive: Boolean): AutoScrollHelper
Enables or disables exclusive handling of touch events during scrolling.
Link copied to clipboard
open fun setMaximumEdges(horizontalMax: Float, verticalMax: Float): AutoScrollHelper
Sets the absolute maximum edge size.
Link copied to clipboard
open fun setMaximumVelocity(horizontalMax: Float, verticalMax: Float): AutoScrollHelper
Sets the absolute maximum scrolling velocity.
Link copied to clipboard
open fun setMinimumVelocity(horizontalMin: Float, verticalMin: Float): AutoScrollHelper
Sets the absolute minimum scrolling velocity.
Link copied to clipboard
open fun setRampDownDuration(durationMillis: Int): AutoScrollHelper
Sets the amount of time after de-activation of auto-scrolling that is takes to slow to a stop.
Link copied to clipboard
open fun setRampUpDuration(durationMillis: Int): AutoScrollHelper
Sets the amount of time after activation of auto-scrolling that is takes to reach target velocity for the current touch position.
Link copied to clipboard
open fun setRelativeEdges(horizontal: Float, vertical: Float): AutoScrollHelper
Sets the activation edge size relative to the host view's dimensions.
Link copied to clipboard
open fun setRelativeVelocity(horizontal: Float, vertical: Float): AutoScrollHelper
Sets the target scrolling velocity relative to the host view's dimensions.