belongs to Maven artifact com.android.support:support-compat:28.0.0-alpha1
AutoScrollHelper
public
abstract
class
AutoScrollHelper
extends Object
implements
View.OnTouchListener
java.lang.Object | |
↳ | android.support.v4.widget.AutoScrollHelper |
![]() |
AutoScrollHelper is a utility class for adding automatic edge-triggered scrolling to Views.
Note: Implementing classes are responsible for overriding the
scrollTargetBy(int, int)
, canTargetScrollHorizontally(int)
, and
canTargetScrollVertically(int)
methods. See
ListViewAutoScrollHelper
for a ListView
-specific implementation.
Activation
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:
- Delay after entering activation area before auto-scrolling begins, see
setActivationDelay(int)
. Default value isgetTapTimeout()
to avoid conflicting with taps. - Location of activation areas, see
setEdgeType(int)
. Default value isEDGE_TYPE_INSIDE_EXTEND
. - Size of activation areas relative to view size, see
setRelativeEdges(float, float)
. Default value is 20% for both vertical and horizontal edges. - Maximum size used to constrain relative size, see
setMaximumEdges(float, float)
. Default value isNO_MAX
.
Scrolling
scrollTargetBy(int, int)
to apply new scrolling offsets.
The following scrolling properties may be configured:
- Acceleration ramp-up duration, see
setRampUpDuration(int)
. Default value is 500 milliseconds. - Acceleration ramp-down duration, see
setRampDownDuration(int)
. Default value is 500 milliseconds. - Target velocity relative to view size, see
setRelativeVelocity(float, float)
. Default value is 100% per second for both vertical and horizontal. - Minimum velocity used to constrain relative velocity, see
setMinimumVelocity(float, float)
. 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(float, float)
. Default value is approximately 25 centimeters or 1575 dips per second.
Summary
Constants | |
---|---|
int |
EDGE_TYPE_INSIDE
Edge type that specifies an activation area starting at the view bounds and extending inward. |
int |
EDGE_TYPE_INSIDE_EXTEND
Edge type that specifies an activation area starting at the view bounds and extending inward. |
int |
EDGE_TYPE_OUTSIDE
Edge type that specifies an activation area starting at the view bounds and extending outward. |
float |
NO_MAX
Constant passed to |
float |
NO_MIN
Constant passed to |
float |
RELATIVE_UNSPECIFIED
Constant passed to |
Public constructors | |
---|---|
AutoScrollHelper(View target)
Creates a new helper for scrolling the specified target view. |
Public methods | |
---|---|
abstract
boolean
|
canTargetScrollHorizontally(int direction)
Override this method to return whether the target view can be scrolled horizontally in a certain direction. |
abstract
boolean
|
canTargetScrollVertically(int direction)
Override this method to return whether the target view can be scrolled vertically in a certain direction. |
boolean
|
isEnabled()
|
boolean
|
isExclusive()
Indicates whether the scroll helper handles touch events exclusively during scrolling. |
boolean
|
onTouch(View v, MotionEvent event)
Handles touch events by activating automatic scrolling, adjusting scroll velocity, or stopping. |
abstract
void
|
scrollTargetBy(int deltaX, int deltaY)
Override this method to scroll the target view by the specified number of pixels. |
AutoScrollHelper
|
setActivationDelay(int delayMillis)
Sets the delay after entering an activation edge before activation of auto-scrolling. |
AutoScrollHelper
|
setEdgeType(int type)
Sets the activation edge type, one of:
|
AutoScrollHelper
|
setEnabled(boolean enabled)
Sets whether the scroll helper is enabled and should respond to touch events. |
AutoScrollHelper
|
setExclusive(boolean exclusive)
Enables or disables exclusive handling of touch events during scrolling. |
AutoScrollHelper
|
setMaximumEdges(float horizontalMax, float verticalMax)
Sets the absolute maximum edge size. |
AutoScrollHelper
|
setMaximumVelocity(float horizontalMax, float verticalMax)
Sets the absolute maximum scrolling velocity. |
AutoScrollHelper
|
setMinimumVelocity(float horizontalMin, float verticalMin)
Sets the absolute minimum scrolling velocity. |
AutoScrollHelper
|
setRampDownDuration(int durationMillis)
Sets the amount of time after de-activation of auto-scrolling that is takes to slow to a stop. |
AutoScrollHelper
|
setRampUpDuration(int durationMillis)
Sets the amount of time after activation of auto-scrolling that is takes to reach target velocity for the current touch position. |
AutoScrollHelper
|
setRelativeEdges(float horizontal, float vertical)
Sets the activation edge size relative to the host view's dimensions. |
AutoScrollHelper
|
setRelativeVelocity(float horizontal, float vertical)
Sets the target scrolling velocity relative to the host view's dimensions. |
Inherited methods | |
---|---|
![]()
java.lang.Object
| |
![]()
android.view.View.OnTouchListener
|
Constants
EDGE_TYPE_INSIDE
int EDGE_TYPE_INSIDE
Edge type that specifies an activation area starting at the view bounds and extending inward. Moving outside the view bounds will stop scrolling.
See also:
Constant Value: 0 (0x00000000)
EDGE_TYPE_INSIDE_EXTEND
int EDGE_TYPE_INSIDE_EXTEND
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.
See also:
Constant Value: 1 (0x00000001)
EDGE_TYPE_OUTSIDE
int EDGE_TYPE_OUTSIDE
Edge type that specifies an activation area starting at the view bounds and extending outward. Moving inside the view bounds will stop scrolling.
See also:
Constant Value: 2 (0x00000002)
NO_MAX
float NO_MAX
Constant passed to setMaximumEdges(float, float)
, setMaximumVelocity(float, float)
,
or setMinimumVelocity(float, float)
. Using this value ensures that the
computed relative value is always used without constraining to a
particular minimum or maximum value.
Constant Value: 3.4028235E38
NO_MIN
float NO_MIN
Constant passed to setMaximumEdges(float, float)
, or
setMaximumVelocity(float, float)
, or setMinimumVelocity(float, float)
. Using this
value ensures that the computed relative value is always used without
constraining to a particular minimum or maximum value.
Constant Value: 0.0
RELATIVE_UNSPECIFIED
float RELATIVE_UNSPECIFIED
Constant passed to setRelativeEdges(float, float)
or
setRelativeVelocity(float, float)
. Using this value ensures that the computed
relative value is ignored and the absolute maximum value is always used.
Constant Value: 0.0
Public constructors
AutoScrollHelper
AutoScrollHelper (View target)
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(boolean)
.
Parameters | |
---|---|
target |
View : The view to automatically scroll.
|
Public methods
canTargetScrollHorizontally
boolean canTargetScrollHorizontally (int direction)
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. |
Returns | |
---|---|
boolean |
true if the target view is able to horizontally scroll in the specified direction. |
canTargetScrollVertically
boolean canTargetScrollVertically (int direction)
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. |
Returns | |
---|---|
boolean |
true if the target view is able to vertically scroll in the specified direction. |
isEnabled
boolean isEnabled ()
Returns | |
---|---|
boolean |
True if this helper is enabled and responding to touch events. |