Android的 - 如何处理两个手指触摸 [英] Android - How to handle two finger touch

查看:992
本文介绍了Android的 - 如何处理两个手指触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档说这有关:

一个姿势开始于一个运动事件ACTION_DOWN提供   的第一指针向下的位置。由于每增加一个指针   该下降或上升​​,该框架将生成一个运动事件   ACTION_POINTER_DOWN或ACTION_POINTER_UP相应。

A gesture starts with a motion event with ACTION_DOWN that provides the location of the first pointer down. As each additional pointer that goes down or up, the framework will generate a motion event with ACTION_POINTER_DOWN or ACTION_POINTER_UP accordingly.

所以,我有我的活动做的onTouchEvent函数的重载:

So i have done the override of onTouchEvent function in my activity:

@Override
public boolean onTouchEvent(MotionEvent MEvent) 
{

    motionaction = MEvent.getAction();

    if(motionaction == MotionEvent.ACTION_DOWN)
    {
        System.out.println("DEBUG MESSAGE POINTER1 " + MEvent.getActionIndex() );
    }

    if(motionaction == MotionEvent.ACTION_POINTER_DOWN)
    {
        System.out.println("DEBUG MESSAGE POINTER2 "  + MEvent.getActionIndex() );
    }

}

不幸的是,如果是从未进入过第二。该活动包含2视图2 OnTouchListener ,我知道,的onTouchEvent 被称为只有当活动的看法不消耗情况,所以我试图返回假的监听并以这种方式,我可以只认第一个手指触摸,但是这避免了监听器接收ACTION_UP事件并没有让我认识了第二个手指触摸。我也试图在听者返回true,但手动后调用的onTouchEvent功能,但这个让我认识到只有第一个手指触摸了。

Unfortunately the second if is never entered. The activity contains 2 view with 2 OnTouchListener, i know that onTouchEvent is called only if the view of the activity don't consume the event so i tried to return false in the listener and in that way i can recognize only the first finger touch but this avoid the listener to receive the ACTION_UP event and don't allow me to recognize the second finger touch. I also tried to return true in the listener but after manually invoke the onTouchEvent function but this allow me to recognize only the first finger touch too.

什么是错误的,我code?

What's wrong in my code ?

推荐答案

我相信你的code缺少像屏蔽操作:

I believe your code is missing the masking operation like:

switch (motionaction & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_POINTER_DOWN:
}

这code应能检查ACTION_POINTER_DOWN。

This code should be able to check for ACTION_POINTER_DOWN.

祝你好运和放大器;告诉我们发生了什么。

Good luck & tell us what happens.

汤米Kwee

这篇关于Android的 - 如何处理两个手指触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆