我的應用需要非常精確的運動測量。不是很精確,但接近它,我想如果用戶的手指在屏幕上,向左或向右移動病房讓我們假設高達100像素,我可以跟蹤它。如何在執行Fling時獲得像素移動?
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視圖,這是唯一可能當我有像素到像素的跟蹤。
任何人指導我如何實現這一目標?