在我的代码中,我想在双击时添加放大并缩小双指点击(如谷歌地图)。我正在使用此代码:
gestureDetector = new GestureDetector(new DoubleTapDetector());
touchListener = new View.OnTouchListener() {
public boolean onTouch(View view, MotionEvent motionEvent) {
final int action = motionEvent.getAction();
final int fingersCount = motionEvent.getPointerCount();
if ((action == MotionEvent.ACTION_POINTER_UP) && (fingersCount == 2)) {
onTwoFingersTap();
return false;
}
return gestureDetector.onTouchEvent(motionEvent);
}
};
双击工作正常,但是当我试图捏住地图时,它会像往常一样缩放,但由于onTwoFingersTap();
也被捕获,因此缩小了一步。
我该如何避免这种情况?
答案 0 :(得分:0)
如果满足您的条件,则返回true:
touchListener = new View.OnTouchListener() {
public boolean onTouch(View view, MotionEvent motionEvent) {
final int action = motionEvent.getAction();
final int fingersCount = motionEvent.getPointerCount();
if ((action == MotionEvent.ACTION_POINTER_UP) && (fingersCount == 2)) {
onTwoFingersTap();
return true;
}
return gestureDetector.onTouchEvent(motionEvent);
}
};