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

后端 未结 7 1944
眼角桃花
眼角桃花 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

    As the previous poster suggested, there are separate events for a single touch pointer up as opposed to action up. The sequence of motionEvents is as follows:

    1. ACTION_DOWN
    2. (ACTION_MOVE)
    3. ACTION_POINTER_DOWN
    4. (ACTION_MOVE)
    5. (ACTION_POINTER_ID_SHIFT)
    6. (repeat for as many fingers as come down)
    7. ACTION_POINTER_UP
    8. (repeat until only one finger remains)
    9. ACTION_UP

    Here's a good resource for understanding multitouch events, but the idea and easiest way to catch them all is to use a switch statement. I use this TouchImageView I found here. what it does is allows for scaling, and panning, and if you just click it, it performs the click, so you can add that processing code into an OnClickListener() or just insert it at line 125.

提交回复
热议问题