public
class
OverScroller
extends Object
java.lang.Object | |
↳ | android.widget.OverScroller |
This class encapsulates scrolling with the ability to overshoot the bounds
of a scrolling operation. This class is a drop-in replacement for
Scroller
in most cases.
Public constructors | |
---|---|
OverScroller(Context context)
Creates an OverScroller with a viscous fluid scroll interpolator and flywheel. |
|
OverScroller(Context context, Interpolator interpolator)
Creates an OverScroller with flywheel enabled. |
|
OverScroller(Context context, Interpolator interpolator, float bounceCoefficientX, float bounceCoefficientY)
Creates an OverScroller with flywheel enabled. |
|
OverScroller(Context context, Interpolator interpolator, float bounceCoefficientX, float bounceCoefficientY, boolean flywheel)
Creates an OverScroller. |
Public methods | |
---|---|
void
|
abortAnimation()
Stops the animation. |
boolean
|
computeScrollOffset()
Call this when you want to know the new location. |
void
|
fling(int startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY, int maxY)
|
void
|
fling(int startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY, int maxY, int overX, int overY)
Start scrolling based on a fling gesture. |
final
void
|
forceFinished(boolean finished)
Force the finished field to a particular value. |
float
|
getCurrVelocity()
Returns the absolute value of the current velocity. |
final
int
|
getCurrX()
Returns the current X offset in the scroll. |
final
int
|
getCurrY()
Returns the current Y offset in the scroll. |
final
int
|
getFinalX()
Returns where the scroll will end. |
final
int
|
getFinalY()
Returns where the scroll will end. |
final
int
|
getStartX()
Returns the start X offset in the scroll. |
final
int
|
getStartY()
Returns the start Y offset in the scroll. |
final
boolean
|
isFinished()
Returns whether the scroller has finished scrolling. |
boolean
|
isOverScrolled()
Returns whether the current Scroller is currently returning to a valid position. |
void
|
notifyHorizontalEdgeReached(int startX, int finalX, int overX)
Notify the scroller that we've reached a horizontal boundary. |
void
|
notifyVerticalEdgeReached(int startY, int finalY, int overY)
Notify the scroller that we've reached a vertical boundary. |
final
void
|
setFriction(float friction)
The amount of friction applied to flings. |
boolean
|
springBack(int startX, int startY, int minX, int maxX, int minY, int maxY)
Call this when you want to 'spring back' into a valid coordinate range. |
void
|
startScroll(int startX, int startY, int dx, int dy, int duration)
Start scrolling by providing a starting point and the distance to travel. |
void
|
startScroll(int startX, int startY, int dx, int dy)
Start scrolling by providing a starting point and the distance to travel. |
Inherited methods | |
---|---|
From
class
java.lang.Object
|
OverScroller (Context context)
Creates an OverScroller with a viscous fluid scroll interpolator and flywheel.
OverScroller (Context context, Interpolator interpolator)
Creates an OverScroller with flywheel enabled.
Parameters | |
---|---|
context |
Context :
The context of this application. |
interpolator |
Interpolator :
The scroll interpolator. If null, a default (viscous) interpolator will
be used.
|
OverScroller (Context context, Interpolator interpolator, float bounceCoefficientX, float bounceCoefficientY)
Creates an OverScroller with flywheel enabled.
Parameters | |
---|---|
context |
Context :
The context of this application. |
interpolator |
Interpolator :
The scroll interpolator. If null, a default (viscous) interpolator will
be used. |
bounceCoefficientX |
float :
A value between 0 and 1 that will determine the proportion of the
velocity which is preserved in the bounce when the horizontal edge is reached. A null value
means no bounce. This behavior is no longer supported and this coefficient has no effect. |
bounceCoefficientY |
float :
Same as bounceCoefficientX but for the vertical direction. This
behavior is no longer supported and this coefficient has no effect.
!deprecated Use {!link #OverScroller(Context, Interpolator, boolean)} instead.
|
OverScroller (Context context, Interpolator interpolator, float bounceCoefficientX, float bounceCoefficientY, boolean flywheel)
Creates an OverScroller.
Parameters | |
---|---|
context |
Context :
The context of this application. |
interpolator |
Interpolator :
The scroll interpolator. If null, a default (viscous) interpolator will
be used. |
bounceCoefficientX |
float :
A value between 0 and 1 that will determine the proportion of the
velocity which is preserved in the bounce when the horizontal edge is reached. A null value
means no bounce. This behavior is no longer supported and this coefficient has no effect. |
bounceCoefficientY |
float :
Same as bounceCoefficientX but for the vertical direction. This
behavior is no longer supported and this coefficient has no effect. |
flywheel |
boolean :
If true, successive fling motions will keep on increasing scroll speed.
!deprecated Use {!link OverScroller(Context, Interpolator, boolean)} instead.
|
void abortAnimation ()
Stops the animation. Contrary to forceFinished(boolean)
,
aborting the animating causes the scroller to move to the final x and y
positions.
See also:
boolean computeScrollOffset ()
Call this when you want to know the new location. If it returns true, the animation is not yet finished.
Returns | |
---|---|
boolean |
void fling (int startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY, int maxY)
Parameters | |
---|---|
startX |
int
|
startY |
int
|
velocityX |
int
|
velocityY |
int
|
minX |
int
|
maxX |
int
|
minY |
int
|
maxY |
int
|
void fling (int startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY, int maxY, int overX, int overY)
Start scrolling based on a fling gesture. The distance traveled 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
unless overX > 0. If overfling is allowed, it will use minX as
a springback boundary. |
maxX |
int :
Maximum X value. The scroller will not scroll past this point
unless overX > 0. If overfling is allowed, it will use maxX as
a springback boundary. |
minY |
int :
Minimum Y value. The scroller will not scroll past this point
unless overY > 0. If overfling is allowed, it will use minY as
a springback boundary. |
maxY |
int :
Maximum Y value. The scroller will not scroll past this point
unless overY > 0. If overfling is allowed, it will use maxY as
a springback boundary. |
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.
|
void forceFinished (boolean finished)
Force the finished field to a particular value. Contrary to
abortAnimation()
, forcing the animation to finished
does NOT cause the scroller to move to the final x and y
position.
Parameters | |
---|---|
finished |
boolean :
The new finished value.
|
float getCurrVelocity ()
Returns the absolute value of the current velocity.
Returns | |
---|---|
float |
The original velocity less the deceleration, norm of the X and Y velocity vector. |
int getCurrX ()
Returns the current X offset in the scroll.
Returns | |
---|---|
int |
The new X offset as an absolute distance from the origin. |
int getCurrY ()
Returns the current Y offset in the scroll.
Returns | |
---|---|
int |
The new Y offset as an absolute distance from the origin. |
int getFinalX ()
Returns where the scroll will end. Valid only for "fling" scrolls.
Returns | |
---|---|
int |
The final X offset as an absolute distance from the origin. |
int getFinalY ()
Returns where the scroll will end. Valid only for "fling" scrolls.
Returns | |
---|---|
int |
The final Y offset as an absolute distance from the origin. |
int getStartX ()
Returns the start X offset in the scroll.
Returns | |
---|---|
int |
The start X offset as an absolute distance from the origin. |
int getStartY ()
Returns the start Y offset in the scroll.
Returns | |
---|---|
int |
The start Y offset as an absolute distance from the origin. |
boolean isFinished ()
Returns whether the scroller has finished scrolling.
Returns | |
---|---|
boolean |
True if the scroller has finished scrolling, false otherwise. |
boolean isOverScrolled ()
Returns whether the current Scroller is currently returning to a valid position.
Valid bounds were provided by the
fling(int, int, int, int, int, int, int, int, int, int)
method.
One should check this value before calling
startScroll(int, int, int, int)
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. |
void notifyHorizontalEdgeReached (int startX, int finalX, int overX)
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.
|
void notifyVerticalEdgeReached (int startY, int finalY, int overY)
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.
|
void setFriction (float friction)
The amount of friction applied to flings. The default value
is getScrollFriction()
.
Parameters | |
---|---|
friction |
float :
A scalar dimension-less value representing the coefficient of
friction.
|
boolean springBack (int startX, int startY, int minX, int maxX, int minY, int maxY)
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 :
Minimum valid Y value |
Returns | |
---|---|
boolean |
true if a springback was initiated, false if startX and startY were already within the valid range. |
void startScroll (int startX, int startY, int dx, int dy, int duration)
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.
|
void startScroll (int startX, int startY, int dx, int dy)
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.
|