如何检测滑动和点击onTouch
方法?我希望在我轻扫时执行两个操作之一,而在我点击时执行其他操作。需要知道如何区分点击和滑动之间的区别。
这是我的代码:
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE) {
mGestureDetector.onTouchEvent(event);
}
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
x1 = event.getX();
y1 = event.getY();
break;
case MotionEvent.ACTION_UP:
x2 = event.getX();
y2 = event.getY();
float deltaX = x2 - x1;
float deltaY = y2 - y1;
if (Math.abs(deltaX) > MIN_DISTANCE) {
mGestureDetector.onTouchEvent(event);
}else if (Math.abs(deltaX) < MIN_DISTANCE) {
mGestureDetector.onTouchEvent(event);
}else if (Math.abs(deltaY) > MIN_DISTANCE) {
mGestureDetector.onTouchEvent(event);
}else if (Math.abs(deltaY) < MIN_DISTANCE) {
mGestureDetector.onTouchEvent(event);
}
break;
}
return true;
}