这应该是一件很简单的事情.用户将手指放在屏幕上并拖动屏幕. onTouch上有两个事件触发:
> MotionEvent.ACTION_DOWN
> MotionEvent.ACTION_MOVE
现在,如何计算ACTION_MOVE手势的速度?用户在手势时拖动手指的速度较慢或者更快,所以我想我需要计算两个中间触点之间的速度:lastTouchedPointX,lastTouchedPointY和event.getX(),event.getY().
以前有人做过吗?
解决方法
@Override public boolean onTouchEvent(MotionEvent event,MapView mapView) { if(event.getAction() == MotionEvent.ACTION_DOWN) { oldX = event.getX(); oldY = event.getY(); //start timer } else if (event.getAction() == MotionEvent.ACTION_UP) { //long timerTime = getTime between two event down to Up newX = event.getX(); newY = event.getY(); float distance = Math.sqrt((newX-oldX) * (newX-oldX) + (newY-oldY) * (newY-oldY)); float speed = distance / timerTime; } }