android api Scroller类翻译

Android Scroller 类详解
本文详细介绍了Android中Scroller类的功能及使用方法。Scroller类主要用于实现滚动动画,通过实例化该类可以收集滚动动画所需的数据,如抛掷手势等,并提供了一系列方法用于控制和获取滚动状态。
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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值