实际上,我尝试使用singleTapConfirmed()
和doubleTap()
执行两项操作。为此,我使用GestureTap
类,其范围从GestureDetector.SimpleOnGestureListener
开始。虽然它可以在某些设备上运行良好,但在某些设备中,例如nougat
和oreo
,它首先接收singleTapConfirmed()
即使是 doubleTap 。我想知道如何解决这个问题。
代码:
class GestureTap extends GestureDetector.SimpleOnGestureListener {
private Context ctx;
public GestureTap(Context ctx) {
this.ctx = ctx;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
Toast.makeText(ctx, ”Double Tap”, Toast.LENGTH_SHORT).show();
return true;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
Toast.makeText(ctx, ”Single Tap”, Toast.LENGTH_SHORT).show();
return true;
}
}
答案 0 :(得分:1)
这可能对您有帮助,
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getActionMasked();
if (action == MotionEvent.ACTION_DOWN) {
final long now = event.getEventTime();
if (now - mTouchTime < ViewConfiguration.getDoubleTapTimeout()) {
mTouchTime = 0;
//doubleClick(event);
} else {
mTouchTime = now;
}
} else if (action == MotionEvent.ACTION_POINTER_DOWN) {
mTouchTime = 0; // no double-tap for other fingers
}
return true;
}