How to detect single touch as well as multi-touch in onTouchEvent()

后端 未结 7 1977
眼角桃花
眼角桃花 2020-12-29 11:19

I used the following code to detect the single finger touch and double finger touch. The code detects the double finger touch (when count==2).

I need t

7条回答
  •  余生分开走
    2020-12-29 12:00

    You must need to user PointerID for MultiTouch. See this Complete Example

    private View.OnTouchListener OnTouchListener = new View.OnTouchListener() {
            public boolean onTouch(View view, MotionEvent event) { 
                int pointerIndex = ((event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT);
                int action = event.getAction() & MotionEvent.ACTION_MASK;
                int pointerId = event.getPointerId(pointerIndex);
                Log.i("", "Pointer ID = " + pointerId);
                switch (action) {
                case MotionEvent.ACTION_POINTER_UP: {
    
                    break;
                }
                }
                return true;
            }
        };
    

提交回复
热议问题