public class OverScroller
extends Object
java.lang.Object | |
↳ | android.widget.OverScroller |
这个类封装了滚动功能,可以超越滚动操作的范围。 在大多数情况下,此课程是Scroller
替代品。
Public constructors |
|
---|---|
OverScroller(Context context) 使用粘性流体滚动内插器和飞轮创建OverScroller。 |
|
OverScroller(Context context, Interpolator interpolator) 创建启用飞轮的OverScroller。 |
|
OverScroller(Context context, Interpolator interpolator, float bounceCoefficientX, float bounceCoefficientY) 创建启用飞轮的OverScroller。 |
|
OverScroller(Context context, Interpolator interpolator, float bounceCoefficientX, float bounceCoefficientY, boolean flywheel) 创建一个OverScroller。 |
Public methods |
|
---|---|
void |
abortAnimation() 停止动画。 |
boolean |
computeScrollOffset() 当你想知道新的位置时调用它。 |
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) 基于一个扔手势开始滚动。 |
final void |
forceFinished(boolean finished) 强制完成的字段为特定值。 |
float |
getCurrVelocity() 返回当前速度的绝对值。 |
final int |
getCurrX() 返回滚动中的当前X偏移量。 |
final int |
getCurrY() 返回滚动中的当前Y偏移量。 |
final int |
getFinalX() 返回滚动结束的位置。 |
final int |
getFinalY() 返回滚动结束的位置。 |
final int |
getStartX() 返回滚动中的起始X偏移量。 |
final int |
getStartY() 返回滚动中的起始Y偏移量。 |
final boolean |
isFinished() 返回滚动器是否完成滚动。 |
boolean |
isOverScrolled() 返回当前Scroller当前是否返回有效位置。 |
void |
notifyHorizontalEdgeReached(int startX, int finalX, int overX) 通知滚动条我们已经达到了水平边界。 |
void |
notifyVerticalEdgeReached(int startY, int finalY, int overY) 通知滚动器我们已达到垂直边界。 |
final void |
setFriction(float friction) 施加在fl上的摩擦量。 |
boolean |
springBack(int startX, int startY, int minX, int maxX, int minY, int maxY) 当你想'回弹'到有效的坐标范围内时调用它。 |
void |
startScroll(int startX, int startY, int dx, int dy, int duration) 通过提供起始点和距离来开始滚动。 |
void |
startScroll(int startX, int startY, int dx, int dy) 通过提供起始点和距离来开始滚动。 |
Inherited methods |
|
---|---|
From class java.lang.Object
|
OverScroller (Context context, Interpolator interpolator)
创建启用飞轮的OverScroller。
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)
创建启用飞轮的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. !deprecated Use {!link #OverScroller(Context, Interpolator, boolean)} instead. |
OverScroller (Context context, Interpolator interpolator, float bounceCoefficientX, float bounceCoefficientY, boolean flywheel)
创建一个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 ()
停止动画。 与forceFinished(boolean)
相反,放弃动画会导致滚动条移动到最终的x和y位置。
也可以看看:
boolean computeScrollOffset ()
当你想知道新的位置时调用它。 如果它返回true,那么动画还没有完成。
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)
基于一个扔手势开始滚动。 行进的距离将取决于投掷的初始速度。
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)
强制完成的字段为特定值。 与abortAnimation()
相反,强制动画完成并不会导致滚动条移动到最终的x和y位置。
Parameters | |
---|---|
finished |
boolean : The new finished value. |
float getCurrVelocity ()
返回当前速度的绝对值。
Returns | |
---|---|
float |
The original velocity less the deceleration, norm of the X and Y velocity vector. |
int getCurrX ()
返回滚动中的当前X偏移量。
Returns | |
---|---|
int |
The new X offset as an absolute distance from the origin. |
int getCurrY ()
返回滚动中的当前Y偏移量。
Returns | |
---|---|
int |
The new Y offset as an absolute distance from the origin. |
int getFinalX ()
返回滚动结束的位置。 仅适用于“一瞥”卷轴。
Returns | |
---|---|
int |
The final X offset as an absolute distance from the origin. |
int getFinalY ()
返回滚动结束的位置。 仅适用于“一瞥”卷轴。
Returns | |
---|---|
int |
The final Y offset as an absolute distance from the origin. |
int getStartX ()
返回滚动中的起始X偏移量。
Returns | |
---|---|
int |
The start X offset as an absolute distance from the origin. |
int getStartY ()
返回滚动中的起始Y偏移量。
Returns | |
---|---|
int |
The start Y offset as an absolute distance from the origin. |
boolean isFinished ()
返回滚动器是否完成滚动。
Returns | |
---|---|
boolean |
True if the scroller has finished scrolling, false otherwise. |
boolean isOverScrolled ()
返回当前Scroller当前是否返回有效位置。 有效边界由fling(int, int, int, int, int, int, int, int, int, int)
方法提供。 在调用startScroll(int, int, int, int)
前应检查该值,因为当前正在进行的插值将恢复有效位置,然后停止。 来电者必须考虑到开始滚动将从超滚动位置开始的事实。
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)
通知滚动条我们已经达到了水平边界。 通常情况下,动画启动时已经知道处理这些信息,例如在对其中一个函数的调用中。 但有些情况下,这种情况不能预先知道。 此功能将根据需要将当前动作和动画从startX转换为finalX。
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)
通知滚动器我们已达到垂直边界。 通常情况下,动画启动时已经知道处理这些信息,例如在对其中一个函数的调用中。 但有些情况下,这种情况不能预先知道。 此函数将动画从startY到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)
施加在fl上的摩擦量。 默认值是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)
当你想'回弹'到有效的坐标范围内时调用它。
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)
通过提供起始点和距离来开始滚动。
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)
通过提供起始点和距离来开始滚动。 滚动将在持续时间内使用默认值250毫秒。
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. |