VelocityTracker
public final class VelocityTrackerextendsObject
| java.lang.Object | |
|---|---|
| ↳ | android.view.VelocityTracker |
added in API level 1.
它是一个跟踪触摸事件滑动速度的帮助类, 用来实现滑动等其他的手势. 当要开始跟踪的时候使用obtain()来检索类的新实例. 使用addMovement(MotionEvent)将您收到的运动事件放在其中. 当你想要确定速度时, 调用computeCurrentVelocity(int), 然后调用getXVelocity(int)和 getYVelocity(int)来检索每个指针id的速度 .
公共方法
addMovement
added in API level 1.
void addMovement (MotionEvent event)
加入用户的移动到跟踪器. 你应该在初始ACTION_DOWN的时候调用它, 然后一直跟随接收到的ACTION_MOVE时间, 最后一个ACTION_UP时终止. 无论你想要哪个事件, 你都可以调用它.
| 参数 | |
|---|---|
| event | MotionEvent: 接受并需要跟踪的MotionEvent . |
clear
added in API level 1.
void clear ()
重置速度跟踪器到初始状态.
computeCurrentVelocity
added in API level 1.
void computeCurrentVelocity (int units)
等同于使用一个最大速度Float.MAX_VALUE来调用computeCurrentVelocity(int, float) .
See also:
computeCurrentVelocity
added in API level 4.
void computeCurrentVelocity (int units, float maxVelocity)
基于已经收集到的点来计算当前的速度. 仅仅在需要获取速度信息的时候才调用它, 它比较耗费资源. 然后你可以使用getXVelocity()和getYVelocity()来获取速度 .
| 参数 | |
|---|---|
| units | int: 你想要的速度的单位. 值为1表示要获取每毫秒移动的像素点, 1000表示要获取每秒移动的像素点, 依次类推. |
| maxVelocity | float: 表示可以被这个方法计算的最大速度值. 这个值的单位必须与units参数的单位一致. 该值必须为正. |
getXVelocity
added in API level 8.
float getXVelocity (int id)
获取最后计算的X速度. 在调用这个方法之前必须先调用computeCurrentVelocity(int).
| 参数 | |
|---|---|
| id | int: 需要返回速度的点. |
| 返回值 | |
|---|---|
| float | 计算的X的速度. |
getXVelocity
added in API level 1.
float getXVelocity ()
获取最后计算的X速度. 在调用这个方法之前必须先调用computeCurrentVelocity(int).
| 返回值 | |
|---|---|
| float | 计算的X的速度. |
getYVelocity
added in API level 8.
float getYVelocity (int id)
获取最后计算的Y速度. 在调用这个方法之前必须先调用computeCurrentVelocity(int).
| 参数 | |
|---|---|
| id | int: 需要返回速度的点. |
| 返回值 | |
|---|---|
| float | 计算的Y的速度. |
getYVelocity
added in API level 1.
float getYVelocity ()
获取最后计算的Y速度. 在调用这个方法之前必须先调用computeCurrentVelocity(int).
| 返回值 | |
|---|---|
| float | 计算的Y的速度. |
obtain
added in API level 1.
VelocityTracker obtain ()
检索一个新的VelocityTracker对象来观察移动的速度. 在结束的要确认调用recycle(). 你通常应该在跟踪一个移动时才保持活动的对象, 以便VelocityTracker可以再其它地方被重用.
| 返回值 | |
|---|---|
| VelocityTracker | 返回一个新的VelocityTracker. |
recycle
added in API level 1.
void recycle ()
Return a VelocityTracker object back to be re-used by others. You must not touch the object after calling this function.
Protected方法
finalize
added in API level 1.
void finalize ()
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides thefinalizemethod to dispose of system resources or to perform other cleanup.
The general contract offinalizeis that it is invoked if and when the Java™ virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. Thefinalizemethod may take any action, including making this object available again to other threads; the usual purpose offinalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.
Thefinalizemethod of classObjectperforms no special action; it simply returns normally. Subclasses ofObjectmay override this definition.
The Java programming language does not guarantee which thread will invoke thefinalizemethod for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.
After thefinalizemethod has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.
Thefinalizemethod is never invoked more than once by a Java virtual machine for any given object.
Any exception thrown by thefinalizemethod causes the finalization of this object to be halted, but is otherwise ignored.
| Throws | |
|---|---|
| Throwable |