Scroller类:存在于android.widget包,直接继承至Object类
类概述:
该类封装了滚动。 你可以使用Scroller或者OverScroller类的实例去收集你需要产生滚动动画的数据,例如抛掷手势。该实例随时不断的追踪滚动效果的偏移量,但是不会自动将这些数据应用到你的view上。你要做的就是以一定的频率去得到并应用这些新的坐标,从而使滑动动画看起来更加平滑。
private Scroller mScroller = new Scroller(context); ... public void zoomIn() { // Revert any animation currently in progress 将当前正在执行的动画复位 mScroller.forceFinished(true); // Start scrolling by providing a starting point and // the distance to travel 设置开始坐标和x,y轴上的偏移量,调用startScroll(。。。) mScroller.startScroll(0, 0, 100, 0); // Invalidate to request a redraw 迫使view重绘 invalidate(); }
if (mScroller.computeScrollOffset()) { // Get current x and y positions int currX = mScroller.getCurrX(); int currY = mScroller.getCurrY(); ... }computeSCrolloffeset()方法会计算当前的偏移量,返回true表示当前滚动动画正在进行中,返回false表示已停止。
该类的方法如下:
void |
abortAnimation()
Stops
the animation.
|
boolean |
computeScrollOffset()
Call
this when you want to know the new location.
|
void |
extendDuration(int
extend)
Extend the scroll animation.
|
void |
fling(int
startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY, int maxY)
Start scrolling based on a fling gesture.
|
final void |
forceFinished(boolean
finished)
Force the finished field to a particular value.
|
float |
getCurrVelocity()
Returns
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 |
getDuration()
Returns
how long the scroll event will take, in milliseconds.
|
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.
|
void |
setFinalX(int
newX)
Sets the final position (X) for this scroller.
|
void |
setFinalY(int
newY)
Sets the final position (Y) for this scroller.
|
final void |
setFriction(float
friction)
The amount of friction applied to flings.
|
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, the distance to travel, and the duration of the scroll.
|
int |
timePassed()
Returns
the time elapsed since the beginning of the scrolling.
|