我的应用程序需要非常精确的运动测量。不是很精确但接近它,我想如果用户将手指放在屏幕上并向左或向右移动假设最多 100 个像素,我可以跟踪它。
class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// right to left swipe
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
//increament in image index & showImage()
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
//decrement in image index & showImage()
}
} catch (Exception e) {
// nothing
}
return false;
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (gestureDetector.onTouchEvent(event))
return true;
else
return false;
}
实际上我有动画帧并且在触摸事件时我想快速移动这些图像,以便用户能够以流畅的方式看到它的 3d 视图,并且只有当我有像素到像素的轨道时才有可能。
任何人指导我如何实现这一目标?