4

我需要在Android我正在开发的应用程序中检测两指点击。我还使用ScaleGestureDetectorandGestureDetector来检测轻击、双击、长按和缩放。

在我的onTouchEvent方法中,我有:

@Override
public boolean onTouchEvent(MotionEvent event) {
    scaleGestureDetector.onTouchEvent(event);
    gestureDetector.onTouchEvent(event);

    switch (event.getActionMasked()) {
    case MotionEvent.ACTION_DOWN:
        activePointerId = event.getPointerId(0);
        break;
    .
    .
    .
    case MotionEvent.ACTION_POINTER_UP:
        int pointerId = event.getPointerId(event.getActionIndex());

        if (pointerId == activePointerId) {
            // change active pointer
        } else if (!scaleDetector.isInProgress() && (event.getPointerCount() == 2)) {
            // handle two-finger tap
        }
        break;
    .
    .
    .

问题是规模也被检测为两指轻敲。关于解决这个问题的任何想法?谢谢!

4

2 回答 2

2

我之前也遇到过这样的问题。最后我必须编写自己的类来扩展 GestureDetector。你可以自己实现缩放。

于 2012-09-05T03:24:51.647 回答
0
private int tap_count=0;
    @Override
        public boolean onTouchEvent(MotionEvent event) {

        int action = event.getAction() & MotionEvent.ACTION_MASK;
        switch(action) {

            case MotionEvent.ACTION_DOWN : {

                ++tap_count;
                Log.d(LOG_TAG, "MotionEvent.ACTION_DOWN "+tap_count);
                break;
            }

            case MotionEvent.ACTION_MOVE : {
                break;
            }

            case MotionEvent.ACTION_POINTER_DOWN : {

                ++tap_count;
                Log.d(LOG_TAG, "MotionEvent.ACTION_POINTER_DOWN "+tap_count);
                break;
            }

            case MotionEvent.ACTION_POINTER_UP : {

                ++tap_count;
                Log.d(LOG_TAG, "MotionEvent.ACTION_POINTER_UP "+tap_count);
                break;
            }

            case MotionEvent.ACTION_UP : {

                --tap_count;
                Log.d(LOG_TAG, "MotionEvent.ACTION_UP "+tap_count);

                if(tap_count == 2){
                    tap_count = 0;
                    Toast.makeText(mContext,"Enableing Accessbility",Toast.LENGTH_SHORT).show();
                    return true;
                }
                break;
            }
        }
        return true;
        }
于 2017-04-12T06:51:29.583 回答