-1

onfling メソッドは、imageview に対してジェスチャ リスナーが実行されていないことです。

4

1 に答える 1

0

このコードを試してください。それは私のために働いた。それはあなたにとってもうまくいくはずです。

private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;    

GestureDetector mGestureDetector = new GestureDetector(new MyGestureDetector());

imgvw.setOnTouchListener(new OnTouchListener() 
{ 
       @Override 
       public boolean onTouch(View v, MotionEvent event) 
       {        
           if(mGestureDetector.onTouchEvent(event);) 
                return true;

            return true;
       } 
});



class MyGestureDetector extends SimpleOnGestureListener {

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        try {
            if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
                return false;
            // right to left swipe
            if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { 
                Log.i(TAG, " ---------- right to left swipe --------- "+" e1.getX() "+e1.getX()+" e2.getX() "+e2.getX());                   
            } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                Log.i(TAG, " ---------- left to right swipe --------- "+" e1.getX() "+e1.getX()+" e2.getX() "+e2.getX());                   
            }
        } catch (Exception exception) {
            Log.i(TAG, exception.getMessage().toString());
        }
        return false;
    }

    @Override
    public boolean onDoubleTap(MotionEvent eMotionEvent) {
        Log.i(TAG, " ------------ double tap occured ---------- ");
        return super.onDoubleTap(eMotionEvent);
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent eMotionEvent) {
        Log.i(TAG, " ------------ single tap occured ---------- ");
        return super.onSingleTapConfirmed(eMotionEvent);
    }
}
于 2012-09-27T10:58:49.303 に答える