Google は、黒人コミュニティに対する人種平等の促進に取り組んでいます。取り組みを見る

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.

open AutoScrollHelper
setRampDownDuration(durationMillis: Int)

Sets the amount of time after de-activation of auto-scrolling that is takes to slow to a stop.

open AutoScrollHelper
setRampUpDuration(durationMillis: Int)

Sets the amount of time after activation of auto-scrolling that is takes to reach target velocity for the current touch position.

open AutoScrollHelper
setRelativeEdges(horizontal: Float, vertical: Float)

Sets the activation edge size relative to the host view's dimensions.

open AutoScrollHelper
setRelativeVelocity(horizontal: Float, vertical: Float)

Sets the target scrolling velocity relative to the host view's dimensions.

Constants

EDGE_TYPE_INSIDE

static val EDGE_TYPE_INSIDE: Int

Edge type that specifies an activation area starting at the view bounds and extending inward. Moving outside the view bounds will stop scrolling.

Value: 0

See Also

EDGE_TYPE_INSIDE_EXTEND

static val EDGE_TYPE_INSIDE_EXTEND: Int

Edge type that specifies an activation area starting at the view bounds and extending inward. After activation begins, moving outside the view bounds will continue scrolling.

Value: 1

See Also

EDGE_TYPE_OUTSIDE

static val EDGE_TYPE_OUTSIDE: Int

Edge type that specifies an activation area starting at the view bounds and extending outward. Moving inside the view bounds will stop scrolling.

Value: 2

See Also

NO_MAX

static val NO_MAX: Float

Constant passed to setMaximumEdges, setMaximumVelocity, or setMinimumVelocity. Using this value ensures that the computed relative value is always used without constraining to a particular minimum or maximum value.

Value: Float.MAX_VALUE

NO_MIN

static val NO_MIN: Float

Constant passed to setMaximumEdges, or setMaximumVelocity, or setMinimumVelocity. Using this value ensures that the computed relative value is always used without constraining to a particular minimum or maximum value.

Value: 0

RELATIVE_UNSPECIFIED

static val RELATIVE_UNSPECIFIED: Float

Constant passed to setRelativeEdges or setRelativeVelocity. Using this value ensures that the computed relative value is ignored and the absolute maximum value is always used.

Value: 0

Public constructors

<init>

AutoScrollHelper(@NonNull target: View)

Creates a new helper for scrolling the specified target view.

The resulting helper may be configured by chaining setter calls and should be set as a touch listener on the target view.

By default, the helper is disabled and will not respond to touch events until it is enabled using setEnabled.

Parameters
target View: The view to automatically scroll.

Public methods

canTargetScrollHorizontally

abstract fun canTargetScrollHorizontally(direction: Int): Boolean

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

Parameters
direction Int: Negative to check scrolling left, positive to check scrolling right.
Return
Boolean true if the target view is able to horizontally scroll in the specified direction.

canTargetScrollVertically

abstract fun canTargetScrollVertically(direction: Int): Boolean

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

Parameters
direction Int: Negative to check scrolling up, positive to check scrolling down.
Return
Boolean true if the target view is able to vertically scroll in the specified direction.

isEnabled

open fun isEnabled(): Boolean
Return
Boolean True if this helper is enabled and responding to touch events.

isExclusive

open fun isExclusive(): Boolean

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

Return
Boolean True if exclusive handling of touch events during scrolling is enabled, false otherwise.

onTouch

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

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

If isExclusive() is false, always returns false so that the host view may handle touch events. Otherwise, returns true when automatic scrolling is active and false otherwise.

scrollTargetBy

abstract f