imageview中的android双击事件

时间:2014-09-20 08:29:47

标签: android events coordinates gesture

以下是我的触摸事件代码

@Override
public boolean onTouchEvent(MotionEvent event) {
    PointF vCenterEnd;
    float vDistEnd;
    flingMomentum = null;
    flingFrom = null;
    // Detect flings
    if (detector == null || detector.onTouchEvent(event)) {
        return true;
    }
    // Abort if not ready
    if (vTranslate == null) {
        return true;
    }
    int touchCount = event.getPointerCount();      
    switch (event.getAction()) {

 case MotionEvent.ACTION_DOWN:
            int x = (int)event.getX();
            int y = (int)event.getY();


        case MotionEvent.ACTION_POINTER_1_DOWN:
        case MotionEvent.ACTION_POINTER_2_DOWN:
            if (touchCount >= 2) {
                // Start pinch to zoom. Calculate distance between touch points and center point of the pinch.
                float distance = distance(event.getX(0), event.getX(1), event.getY(0), event.getY(1));
                scaleStart = scale;
                vDistStart = distance;
                vTranslateStart = new PointF(vTranslate.x, vTranslate.y);
                vCenterStart = new PointF((event.getX(0) + event.getX(1))/2, (event.getY(0) + event.getY(1))/2);
                isZooming = true;
            } else {
                // Start one-finger pan

                vTranslateStart = new PointF(vTranslate.x, vTranslate.y);
                vCenterStart = new PointF(event.getX(), event.getY());
            }
        case MotionEvent.ACTION_MOVE:
            if (touchCount >= 2 && isZooming) {
                // Calculate new distance between touch points, to scale and pan relative to start values.
                vDistEnd = distance(event.getX(0), event.getX(1), event.getY(0), event.getY(1));
                vCenterEnd = new PointF((event.getX(0) + event.getX(1))/2, (event.getY(0) + event.getY(1))/2);
                scale = Math.min(maxScale, (vDistEnd / vDistStart) * scaleStart);

                // Translate to place the source image coordinate that was at the center of the pinch at the start
                // at the center of the pinch now, to give simultaneous pan + zoom.
                float vLeftStart = vCenterStart.x - vTranslateStart.x;
                float vTopStart = vCenterStart.y - vTranslateStart.y;
                float vLeftNow = vLeftStart * (scale/scaleStart);
                float vTopNow = vTopStart * (scale/scaleStart);
                vTranslate.x = vCenterEnd.x - vLeftNow;
                vTranslate.y = vCenterEnd.y - vTopNow;

                fitToBounds();
                refreshRequiredTiles(false);
            } else if (!isZooming) {
                // One finger pan - translate the image
                vTranslate.x = vTranslateStart.x + (event.getX() - vCenterStart.x);
                vTranslate.y = vTranslateStart.y + (event.getY() - vCenterStart.y);
                fitToBounds();
                refreshRequiredTiles(false);
            }
            invalidate();
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_POINTER_UP:

        case MotionEvent.ACTION_POINTER_2_UP:
            if (event.getPointerCount() < 2) {
                isZooming = false;
            }
            // Trigger load of tiles now required
            refreshRequiredTiles(true);
            break;
    }
    return true;
}

我试图实现双击,双击时会覆盖水龙头的坐标,但无法确定我需要插入的事件

我搜索过代码的所有例子都与此不同,希望你能指出我正确的方向

感谢任何帮助。

标记

0 个答案:

没有答案