android onTouchEvent

触摸屏幕时,没搞懂每个事件的启动顺序。本文记录onTouchEvent发生时,每个事件启动的顺序。

测试代码

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        int pointCount = event.getPointerCount();
        switch (pointCount) {
            case 1:
                switch (event.getAction() & MotionEvent.ACTION_MASK) {
                    case MotionEvent.ACTION_DOWN:
                        Log.e("touch", "1 down-------");
                        break;
                    case MotionEvent.ACTION_MOVE:
                        Log.e("touch", "1 move-------");
                        break;
                    case MotionEvent.ACTION_UP:
                        Log.e("touch", "1 up-------");
                        break;
                }
            break;
            case 2:
        switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_POINTER_DOWN:
                Log.e("touch", "2 down-------");
                break;
            case MotionEvent.ACTION_MOVE:
                Log.e("touch", "2 move-------");
                break;
            case MotionEvent.ACTION_POINTER_UP:
                Log.e("touch", "2 up-------");
                break;
            }
                break;
            case 3:
                switch (event.getAction() & MotionEvent.ACTION_MASK) {
                    case MotionEvent.ACTION_POINTER_DOWN:
                        Log.e("touch", "3 down-------");
                        break;
                    case MotionEvent.ACTION_MOVE:
                        Log.e("touch", "3 move-------");
                        break;
                    case MotionEvent.ACTION_POINTER_UP:
                        Log.e("touch", "3 up-------");
                        break;
                }
                break;
        }
        return true;
输出结果

单点触摸

07-17 11:29:38.651 15874-15874/com.example.tony.ring E/touch: 1 down-------
07-17 11:29:38.664 15874-15874/com.example.tony.ring E/touch: 1 move-------
07-17 11:29:38.677 15874-15874/com.example.tony.ring E/touch: 1 up-------

两点触摸

07-17 11:30:36.610 15874-15874/com.example.tony.ring E/touch: 1 down-------
07-17 11:30:36.611 15874-15874/com.example.tony.ring E/touch: 1 move-------
07-17 11:30:36.612 15874-15874/com.example.tony.ring E/touch: 2 down-------
07-17 11:30:36.637 15874-15874/com.example.tony.ring E/touch: 2 move-------
07-17 11:30:36.637 15874-15874/com.example.tony.ring E/touch: 2 up-------
07-17 11:30:36.638 15874-15874/com.example.tony.ring E/touch: 1 up-------
或者
07-17 11:31:43.909 15874-15874/com.example.tony.ring E/touch: 1 down-------
07-17 11:31:43.910 15874-15874/com.example.tony.ring E/touch: 2 down-------
07-17 11:31:43.942 15874-15874/com.example.tony.ring E/touch: 2 move-------
07-17 11:31:43.943 15874-15874/com.example.tony.ring E/touch: 2 up-------
07-17 11:31:43.943 15874-15874/com.example.tony.ring E/touch: 1 up-------

三点触摸

07-17 11:32:46.598 15874-15874/com.example.tony.ring E/touch: 1 down-------
07-17 11:32:46.602 15874-15874/com.example.tony.ring E/touch: 2 down-------
07-17 11:32:46.604 15874-15874/com.example.tony.ring E/touch: 3 down-------
07-17 11:32:46.604 15874-15874/com.example.tony.ring E/touch: 3 move-------
07-17 11:32:46.604 15874-15874/com.example.tony.ring E/touch: 3 up-------
07-17 11:32:46.605 15874-15874/com.example.tony.ring E/touch: 2 move-------
07-17 11:32:46.605 15874-15874/com.example.tony.ring E/touch: 2 up-------
07-17 11:32:46.607 15874-15874/com.example.tony.ring E/touch: 1 up-------
或者
07-17 11:33:06.252 15874-15874/com.example.tony.ring E/touch: 1 down-------
07-17 11:33:06.254 15874-15874/com.example.tony.ring E/touch: 2 down-------
07-17 11:33:06.256 15874-15874/com.example.tony.ring E/touch: 3 down-------
07-17 11:33:06.271 15874-15874/com.example.tony.ring E/touch: 3 move-------
07-17 11:33:06.288 15874-15874/com.example.tony.ring E/touch: 3 move-------
07-17 11:33:06.288 15874-15874/com.example.tony.ring E/touch: 3 up-------
07-17 11:33:06.289 15874-15874/com.example.tony.ring E/touch: 2 up-------
07-17 11:33:06.289 15874-15874/com.example.tony.ring E/touch: 1 up-------

多点触摸时,有没有ACTION_MOVE的动作不能保证,

点击时肯定先是

  1 down -> 2 down -> 3 down

释放时

  3 up -> 2 up -> 1 up

Author

Tony Liu

2016-7-17, Shenzhen

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值