Android_code_多点触摸

    
    /** 根据打印发现:即使没有移动也一直在发送移动的事件 */
    public void handleMultiTouchEvent01(MotionEvent e) {

        final int action = e.getActionMasked();
        final int actionIndex = e.getActionIndex();
        int x, y;

        switch (action) {

            // 第一个 手指 初次接触到屏幕 时触发。
            case MotionEvent.ACTION_DOWN:

                // 记录初始化的坐标
                x = (int) (e.getX() + 0.5f);
                y = (int) (e.getY() + 0.5f);
                Logcat.d(TAG, String.format("DOWN index: %d x: %d y: %d", actionIndex, x, y));
                break;

            // 有非主要的手指按下(即按下之前已经有手指在屏幕上)。
            case MotionEvent.ACTION_POINTER_DOWN:

                x = (int) (e.getX(actionIndex) + 0.5f);
                y = (int) (e.getY(actionIndex) + 0.5f);
                Logcat.d(TAG, String.format("DOWN index: %d x: %d y: %d", actionIndex, x, y));

                break;

            // 手指 在屏幕上滑动 时触发,会多次触发。
            case MotionEvent.ACTION_MOVE:

                for (int i = 0; i < e.getPointerCount(); i++) {
                    x = (int) (e.getX(i) + 0.5f);
                    y = (int) (e.getY(i) + 0.5f);
                    Logcat.d(TAG, String.format("MOVE index: %d x: %d y: %d", i, x, y));
                }

                break;

            // 有非主要的手指抬起(即抬起之后仍然有手指在屏幕上)。
            case MotionEvent.ACTION_POINTER_UP:

                x = (int) (e.getX(actionIndex) + 0.5f);
                y = (int) (e.getY(actionIndex) + 0.5f);
                Logcat.d(TAG, String.format("UP index: %d x: %d y: %d", actionIndex, x, y));
                break;

            // 最后一个 手指 离开屏幕 时触发。
            case MotionEvent.ACTION_UP:
                x = (int) (e.getX(actionIndex) + 0.5f);
                y = (int) (e.getY(actionIndex) + 0.5f);
                Logcat.d(TAG, String.format("UP index: %d x: %d y: %d", actionIndex, x, y));
                break;

        }


    }

参考资料:

Android多点触控详解_阿亮的博客-CSDN博客_android 多点触摸

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值