当手指向上时,ACTION_UP不会触发

时间:2013-11-04 21:27:27

标签: android ontouchlistener

所以,我在这里讨论了所有关于这个问题的讨论。 我返回true,没有处理ACTION_UP的其他地方。

我使用线程来处理图形和计算,但我无法弄清楚为什么这很重要。

这是我对onTouch方法的实现:

@Override
public boolean onTouch(View v, MotionEvent event) {
    synchronized (this) {
        int action = event.getAction() & MotionEvent.ACTION_MASK;
        int pointerIndex = event.getAction()
                & MotionEvent.ACTION_POINTER_INDEX_MASK >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
        int pointerCount = event.getPointerCount();
        TouchEvent touchEvent;
        for (int i = 0; i < MAX_TOUCHPOINTS; i++) {
            if (i >= pointerCount) {
                isTouched[i] = false;
                id[i] = -1;
                continue;
            }
            int pointerId = event.getPointerId(i);
            if ((event.getAction() != MotionEvent.ACTION_MOVE && i != pointerIndex)) {
                // if its an up/down/cancel/out event mask the id to see if
                // we should process it for this touch point
                continue;
            }
            Log.i("Logged TouchEvents", "" + event.getAction());
            switch (action) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_POINTER_DOWN:
                touchEvent = touchEventPool.newObject();
                touchEvent.type = TouchEvent.TOUCH_DOWN;
                touchEvent.pointer = pointerId;
                touchEvent.x = touchX[i] = (int) (event.getX() * scaleX);
                touchEvent.y = touchY[i] = (int) (event.getY() * scaleY);
                isTouched[i] = true;
                id[i] = pointerId;
                toucheventBuffer.add(touchEvent);
                Log.d("MultiTouchHandler", "TouchEvent.Down ("
                        + touchEvent.x + "," + touchEvent.y + ")");

                break;

            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_POINTER_UP:
            case MotionEvent.ACTION_CANCEL:
                touchEvent = touchEventPool.newObject();
                touchEvent.type = TouchEvent.TOUCH_UP;
                touchEvent.pointer = pointerId;
                touchEvent.x = touchX[i] = (int) (event.getX() * scaleX);
                touchEvent.y = touchY[i] = (int) (event.getY() * scaleY);
                isTouched[i] = false;
                id[i] = -1;
                toucheventBuffer.add(touchEvent);
                Log.d("MultiTouchHandler", "TouchEvent.TouchUp ("
                        + touchEvent.x + "," + touchEvent.y + ")");
                break;

            case MotionEvent.ACTION_MOVE:
                touchEvent = touchEventPool.newObject();
                touchEvent.type = TouchEvent.TOUCH_DRAG;
                touchEvent.pointer = pointerId;
                touchEvent.x = touchX[i] = (int) (event.getX() * scaleX);
                touchEvent.y = touchY[i] = (int) (event.getY() * scaleY);
                isTouched[i] = true;
                id[i] = pointerId;
                toucheventBuffer.add(touchEvent);
                Log.d("MultiTouchHandler", "TouchEvent.TouchDrag ("
                        + touchEvent.x + "," + touchEvent.y + ")");
                break;
            default:
                break;

            }

        }

    }
    return true;
}

请注意,变量'action'(在开关/ case之前检查)永远不等于1(ACTION_UP)

提前致谢。

0 个答案:

没有答案