Constructor and Description |
---|
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,
boolean flywheel)
Creates an OverScroller.
|
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.
|
Modifier and Type | Method and Description |
---|---|
void |
abortAnimation()
Stops the animation.
|
boolean |
computeScrollOffset()
Call this when you want to know the new location.
|
void |
extendDuration(int extend)
Deprecated.
OverScrollers don't necessarily have a fixed duration.
Instead of setting a new final position and extending
the duration of an existing scroll, use startScroll
to begin a new animation.
|
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.
|
void |
forceFinished(boolean finished)
Force the finished field to a particular value.
|
float |
getCurrVelocity()
Returns the absolute value of the current velocity.
|
int |
getCurrX()
Returns the current X offset in the scroll.
|
int |
getCurrY()
Returns the current Y offset in the scroll.
|
int |
getDuration()
Deprecated.
OverScrollers don't necessarily have a fixed duration.
This function will lie to the best of its ability.
|
int |
getFinalX()
Returns where the scroll will end.
|
int |
getFinalY()
Returns where the scroll will end.
|
int |
getStartX()
Returns the start X offset in the scroll.
|
int |
getStartY()
Returns the start Y offset in the scroll.
|
boolean |
isFinished()
Returns whether the scroller has finished scrolling.
|
boolean |
isOverScrolled()
Returns whether the current Scroller is currently returning to a valid position.
|
boolean |
isScrollingInDirection(float xvel,
float yvel) |
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.
|
void |
setFinalX(int newX)
Deprecated.
OverScroller's final position may change during an animation.
Instead of setting a new final position and extending
the duration of an existing scroll, use startScroll
to begin a new animation.
|
void |
setFinalY(int newY)
Deprecated.
OverScroller's final position may change during an animation.
Instead of setting a new final position and extending
the duration of an existing scroll, use startScroll
to begin a new animation.
|
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)
Start scrolling by providing a starting point and the distance to travel.
|
void |
startScroll(int startX,
int startY,
int dx,
int dy,
int duration)
Start scrolling by providing a starting point and the distance to travel.
|
int |
timePassed()
Returns the time elapsed since the beginning of the scrolling.
|
public OverScroller(Context context)
context
- public OverScroller(Context context, Interpolator interpolator)
context
- The context of this application.interpolator
- The scroll interpolator. If null, a default (viscous) interpolator will
be used.public OverScroller(Context context, Interpolator interpolator, boolean flywheel)
context
- The context of this application.interpolator
- The scroll interpolator. If null, a default (viscous) interpolator will
be used.flywheel
- If true, successive fling motions will keep on increasing scroll speed.public OverScroller(Context context, Interpolator interpolator, float bounceCoefficientX, float bounceCoefficientY)
context
- The context of this application.interpolator
- The scroll interpolator. If null, a default (viscous) interpolator will
be used.bounceCoefficientX
- 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
- 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.public OverScroller(Context context, Interpolator interpolator, float bounceCoefficientX, float bounceCoefficientY, boolean flywheel)
context
- The context of this application.interpolator
- The scroll interpolator. If null, a default (viscous) interpolator will
be used.bounceCoefficientX
- 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
- Same as bounceCoefficientX but for the vertical direction. This
behavior is no longer supported and this coefficient has no effect.flywheel
- If true, successive fling motions will keep on increasing scroll speed.
!deprecated Use {!link OverScroller(Context, Interpolator, boolean)} instead.public final void setFriction(float friction)
ViewConfiguration.getScrollFriction()
.friction
- A scalar dimension-less value representing the coefficient of
friction.public final boolean isFinished()
public final void forceFinished(boolean finished)
abortAnimation()
, forcing the animation to finished
does NOT cause the scroller to move to the final x and y
position.finished
- The new finished value.public final int getCurrX()
public final int getCurrY()
public float getCurrVelocity()
public final int getStartX()
public final int getStartY()
public final int getFinalX()
public final int getFinalY()
@Deprecated public final int getDuration()
@Deprecated public void extendDuration(int extend)
setFinalX(int)
or setFinalY(int)
.extend
- Additional time to scroll in milliseconds.setFinalX(int)
,
setFinalY(int)
@Deprecated public void setFinalX(int newX)
newX
- The new X offset as an absolute distance from the origin.extendDuration(int)
,
setFinalY(int)
@Deprecated public void setFinalY(int newY)
newY
- The new Y offset as an absolute distance from the origin.extendDuration(int)
,
setFinalX(int)
public boolean computeScrollOffset()
public void startScroll(int startX, int startY, int dx, int dy)
startX
- Starting horizontal scroll offset in pixels. Positive
numbers will scroll the content to the left.startY
- Starting vertical scroll offset in pixels. Positive numbers
will scroll the content up.dx
- Horizontal distance to travel. Positive numbers will scroll the
content to the left.dy
- Vertical distance to travel. Positive numbers will scroll the
content up.public void startScroll(int startX, int startY, int dx, int dy, int duration)
startX
- Starting horizontal scroll offset in pixels. Positive
numbers will scroll the content to the left.startY
- Starting vertical scroll offset in pixels. Positive numbers
will scroll the content up.dx
- Horizontal distance to travel. Positive numbers will scroll the
content to the left.dy
- Vertical distance to travel. Positive numbers will scroll the
content up.duration
- Duration of the scroll in milliseconds.public boolean springBack(int startX, int startY, int minX, int maxX, int minY, int maxY)
startX
- Starting X coordinatestartY
- Starting Y coordinateminX
- Minimum valid X valuemaxX
- Maximum valid X valueminY
- Minimum valid Y valuemaxY
- Minimum valid Y valuepublic void fling(int startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY, int maxY)
public void fling(int startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY, int maxY, int overX, int overY)
startX
- Starting point of the scroll (X)startY
- Starting point of the scroll (Y)velocityX
- Initial velocity of the fling (X) measured in pixels per
second.velocityY
- Initial velocity of the fling (Y) measured in pixels per
secondminX
- 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
- 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
- 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
- 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
- Overfling range. If > 0, horizontal overfling in either
direction will be possible.overY
- Overfling range. If > 0, vertical overfling in either
direction will be possible.public void notifyHorizontalEdgeReached(int startX, int finalX, int overX)
startX
- Starting/current X positionfinalX
- Desired final X positionoverX
- Magnitude of overscroll allowed. This should be the maximum
desired distance from finalX. Absolute value - must be positive.public void notifyVerticalEdgeReached(int startY, int finalY, int overY)
startY
- Starting/current Y positionfinalY
- Desired final Y positionoverY
- Magnitude of overscroll allowed. This should be the maximum
desired distance from finalY. Absolute value - must be positive.public boolean isOverScrolled()
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.public void abortAnimation()
forceFinished(boolean)
,
aborting the animating causes the scroller to move to the final x and y
positions.forceFinished(boolean)
public int timePassed()
public boolean isScrollingInDirection(float xvel, float yvel)