Android抓住两个手指点击MapView

时间:2011-11-21 03:17:34

标签: java android android-mapview gesture pinch

在我的代码中,我想在双击时添加放大并缩小双指点击(如谷歌地图)。我正在使用此代码:

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();也被捕获,因此缩小了一步。

我该如何避免这种情况?

1 个答案:

答案 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);     
    } 
 };