Android 速度检测demo
16lz
2021-01-23
package app.test;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.MotionEvent;import android.view.VelocityTracker;public class Test extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } private VelocityTracker vTracker = null; public boolean onTouchEvent(MotionEvent event) { int action = event.getAction(); switch(action) { case MotionEvent.ACTION_DOWN: if(vTracker == null) { vTracker = VelocityTracker.obtain(); } else { vTracker.clear(); } vTracker.addMovement(event); break; case MotionEvent.ACTION_MOVE: vTracker.addMovement(event); vTracker.computeCurrentVelocity(1000); Log.v("", "X velocity is " + vTracker.getXVelocity() +" pixels per second"); Log.v("", "Y velocity is " + vTracker.getYVelocity() +" pixels per second"); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: vTracker.recycle(); break; } return true; }}
vTracker.computeCurrentVelocity(1000)是设置计量单位,但是是毫秒。
vTracker.getXVelocity()
vTracker.getYVelocity()
得出来的值是多少像素每秒.
更多相关文章
- Android for opencv(1)android使用opencv基本操作:读写 图片,操作像
- 如何确定在web页面上呈现的字符串的长度(以像素为单位)?
- Html css缩放会将大小改变几个像素
- 将2d数组数据视为定义形状的像素——是否可能创建内部和表面?
- Java图片识别技术原理-只取图片像素。。。