singletap-touch-Erkennung in der Ontouch-Methode der view

Brauchte ich eine singletap-touch-Erkennung auf meiner eigenen Sicht der ontouch-Methode. Ich habe versucht, immer die x-und y-Werte in den beiden ACTION-DOWN-und-ACTION-und ACTION-UP habe ich eine Bedingung, dass, wenn einer der Werte von X und Y in ACTIONDOWN-und ACTION - - - BIS gleich, dann nehmen Sie es als eine einzige Tippen.

Mein code ist wie folgt

@Override
public boolean onTouchEvent(MotionEvent ev) {
   if (!mSupportsZoom && !mSupportsPan) return false;

    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;  //here i get x and y values in action down
        mLastTouchY = y;
        mActivePointerId = ev.getPointerId(0);

        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final int pointerIndex = ev.findPointerIndex(mActivePointerId);
        final float x = ev.getX(pointerIndex);
        final float y = ev.getY(pointerIndex);

        if (mSupportsPan && !mScaleDetector.isInProgress()) {
            final float dx = x - mLastTouchX;
            final float dy = y - mLastTouchY;

            mPosX += dx;
            mPosY += dy;
            //mFocusX = mPosX;
            //mFocusY = mPosY;

            invalidate();
        }

        mLastTouchX = x;
        mLastTouchY = y;

        break;
    }

    case MotionEvent.ACTION_UP: {

        final float x = ev.getX();
        final float y = ev.getY();

        touchupX=x;   //here is get x and y values at action up
        touchupY=y; 

        if(mLastTouchX == touchupX && mLastTouchY == touchupY){  //my condition if both the x and y values are same .

            PinchZoomPanActivity2.tapped1(this.getContext(), 100); //my method if the singletap is detected

        }
        else{

        }

        mActivePointerId = INVALID_POINTER_ID;

        break;
    }

    case MotionEvent.ACTION_CANCEL: {
        mActivePointerId = INVALID_POINTER_ID;
        break;
    }

    case MotionEvent.ACTION_POINTER_UP: {
        final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) 
                >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
        final int pointerId = ev.getPointerId(pointerIndex);
        if (pointerId == mActivePointerId) {

            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mLastTouchX = ev.getX(newPointerIndex);
            mLastTouchY = ev.getY(newPointerIndex);
            mActivePointerId = ev.getPointerId(newPointerIndex);
        }
        break;
    }
    }

    return true;
}

aber kann ich nicht bekommen es getan. Ich meine, bei jeder Aktion, meine Methode aufgerufen wird. auch wenn die x-und y-Werte der beiden actionup und actiondown sind nicht dasselbe. und ich denke, ich brauche auch etwas Auswahl, um die singletap, wie wir den Kontakt mit unserem finger auf dem Bildschirm. Kann mir jemand empfehlen einige Möglichkeiten?

Es wird nie in der exakt gleichen Stelle - Ihr finger immer leicht bewegt. Verwenden Sie einen range-check - stellen Sie sicher, dass abs(upLoc-downLoc) < 5.
ich verwenden müssen, prüfen Sie die Reichweite, aber ich Verstand nicht Ihr"abs(upLoc-downLoc)<5".
abs=absolut-Wert. Das bedeutet also, dass wenn der Speicherort wurde geändert von weniger als 5 Pixel.

InformationsquelleAutor Sandeep R | 2013-08-01

Schreibe einen Kommentar