Je suis en train de faire mon point de vue de travailler avec de nombreuses façons différentes, il devrait y avoir:Comment faire un double tap et un panoramique en même temps, sur Android?
- Multitouch pour zoomer
- Touchlistener pour un balayage panoramique
- Doubleclick pour restaurer zoom
- ou si elle est déjà restauré il va zoomer l'endroit où le double-clic était.
À l'heure actuelle, tout fonctionne d'autre, mais quand je DOUBLECLICK et continue vers le bas et cliquez second continuer déplacer le code fonctionne de cette façon d'abord restores/zooms
puis panning starts
. Donc, à cause de l'échelle de zoom, il va parfois d'abord changer la taille de la toile, puis commencer le panoramique. Que dois-je faire pour activer le panoramique après un double clic remarqué? Ou quelque chose comme vérifier si le dernier clic de double clic continue de bouger et de sauter la chose de zoom/restauration? Mon code ressemble à ceci atm. Et j'essaie de retourner false après doubleclick mais cela n'a pas vraiment d'effet ... Serait-il quelque chose comme la configuration ignoreMultiTouch
à true
, mais en double-cliquant ou en panoramique?
@Override
public boolean onTouchEvent(MotionEvent ev) {
if(mgestureDetector.onTouchEvent(ev)){
mOnTouchEventWorkingArray[0] = ev.getX();
mOnTouchEventWorkingArray[1] = ev.getY();
mOnTouchEventWorkingArray = scaledPointsToScreenPoints(mOnTouchEventWorkingArray);
ev.setLocation(mOnTouchEventWorkingArray[0], mOnTouchEventWorkingArray[1]);
mScaleDetector.onTouchEvent(ev);
final int action = ev.getAction();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN: {
final float x = ev.getX();
final float y = ev.getY();
mLastTouchX = x;
mLastTouchY = y;
// Save the ID of this pointer
mActivePointerId = ev.getPointerId(0);
break;
}
case MotionEvent.ACTION_MOVE: {
// Find the index of the active pointer and fetch its position
final int pointerIndex = ev.findPointerIndex(mActivePointerId);
final float x = ev.getX(pointerIndex);
final float y = ev.getY(pointerIndex);
final float dx = x - mLastTouchX;
final float dy = y - mLastTouchY;
mPosX += dx;
mPosY += dy;
mTranslateMatrix.preTranslate(dx, dy);
mTranslateMatrix.invert(mTranslateMatrixInverse);
mLastTouchX = x;
mLastTouchY = y;
normal = false;
invalidate();
break;
}
case MotionEvent.ACTION_UP: {
mActivePointerId = INVALID_POINTER_ID;
break;
}
case MotionEvent.ACTION_CANCEL: {
mActivePointerId = INVALID_POINTER_ID;
break;
}
case MotionEvent.ACTION_POINTER_UP: {
// Extract the index of the pointer that left the touch sensor
final int pointerIndex = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
final int pointerId = ev.getPointerId(pointerIndex);
if (pointerId == mActivePointerId) {
// This was our active pointer going up. Choose a new
// active pointer and adjust accordingly.
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mLastTouchX = ev.getX(newPointerIndex);
mLastTouchY = ev.getY(newPointerIndex);
mActivePointerId = ev.getPointerId(newPointerIndex);
}
break;
}
}
}
return true;
}
private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
@Override
public boolean onScale(ScaleGestureDetector detector) {
mScaleFactor *= detector.getScaleFactor();
if (detector.isInProgress()) {
mFocusX = detector.getFocusX();
mFocusY = detector.getFocusY();
}
mScaleFactor = Math.max(0.75f, Math.min(mScaleFactor, 3.0f));
mScaleMatrix.setScale(mScaleFactor, mScaleFactor,
mFocusX, mFocusY);
mScaleMatrix.invert(mScaleMatrixInverse);
invalidate();
requestLayout();
return true;
}
}
private class GestureListener extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onDown(MotionEvent e) {
return true;
}
// event when double tap occurs
@Override
public boolean onDoubleTap(MotionEvent e) {
if (!normal) {
restore();
} else {
zoomToSpot(e);
}
return false;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
return true;
}
}