Android的多点触控:ACTION_UP并不总是叫什么名字? [英] Android multitouch: ACTION_UP not always called?

查看:135
本文介绍了Android的多点触控:ACTION_UP并不总是叫什么名字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了被处理的多点触控视图中的一个Android应用程序。我基本上跟踪可能发生的像ACTION_UP,ACTION_MOVE,...在View类我覆盖onTouch方法如下所示的几个MotionEvents:

I have developed an Android application that is handling multitouch in a view. I basically track the several MotionEvents that can occur like ACTION_UP, ACTION_MOVE, ... My overwritten onTouch method in the View class looks like this:

public boolean onTouch(View view, MotionEvent event) 
{
    int action = event.getAction() & MotionEvent.ACTION_MASK;

    if (action == MotionEvent.ACTION_DOWN) {
        float x = event.getX();
        handleTouchStart(view, x);
    } else if (action == MotionEvent.ACTION_UP) {
        float x = event.getX();
        handleTouchEnded(view, x);
    } else if (action == MotionEvent.ACTION_POINTER_DOWN) {
        int pointer = (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT;
        float x = event.getX(pointer);
        handleTouchStart(view, x);
    } else if (action == MotionEvent.ACTION_POINTER_UP) {
        int pointer = (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT;
        float x = event.getX(pointer);
        handleTouchEnded(view, x);
    } else if (action == MotionEvent.ACTION_MOVE) {
        int pointer = (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT;
        float x = event.getX(pointer);
        handleTouchMoved(view, x);
    }

    return true;
}

在我的手机(三星Galaxy S),这个完美的作品。对于每一个handleTouchStart(),适当的handleTouchEnded()被调用。这是我的应用程序至关重要。它是一个二维的sidescroller有转向区域在屏幕的左下部。如果 - 因某种原因 - 当用户拿起从触摸屏手指的handleTouchEnded()方法时不叫,玩家的角色将继续运行。

On my phone (Samsung Galaxy S), this works flawlessly. For every handleTouchStart(), the appropriate handleTouchEnded() is called. This is crucial for my app. It's a 2D sidescroller with a steering area in the left lower portion of the screen. If - for some reason - the handleTouchEnded() method is not called when the user lifts a finger from the touchscreen, the player's character continues running.

我收到了来自玩家在其他设备(如HTC Desire的),在极少数情况下,性格确实持续的方向运行,即使他们举起他们的手指从转向区域在屏幕上的报告。我认为,如果handleTouchEnded()将不会调用这又意味着没有ACTION_UP(或ACTION_POINTER_UP)事件产生,这只能发生

I've received reports from players on other devices (like the HTC Desire) that in rare occasions, the character does indeed continue running in a direction even if they lifted their finger from the steering area on the screen. I concluded that this can only happen if handleTouchEnded() is not called which in turn means that no ACTION_UP (or ACTION_POINTER_UP) event is generated.

有没有对多点触摸的支持设备的具体实现?有没有保证每个ACTION_DOWN(或ACTION_POINTER_DOWN)MotionEvent,适当ACTION_UP(或ACTION_POINTER_UP)MotionEvent叫?还是我失去了一些东西?是我onTouch实现甚至是否正确?

Are there device specific implementations of multitouch support? Is there no guarantee that for each ACTION_DOWN (or ACTION_POINTER_DOWN) MotionEvent, an appropriate ACTION_UP (or ACTION_POINTER_UP) MotionEvent is called? Or am I missing something? Is my onTouch implementation even correct?

我的更广泛的问题是:是否有更好的方法来处理多点触控触摸屏输入的动作-games?我基本上模仿手柄的转向横的左边和右边的控制。我发现,Android的UI按钮都不能提供足够的灵活性,因为他们无法跟踪preSS和onRelease事件......或许他们?

My broader question would be: are there better ways to handle multitouch touchscreen input for "action"-games? I'm basically mimicking the left and right controls of a gamepad's steering cross. I've found that Android's UI buttons don't offer enough flexibility because they can't track onPress and onRelease events... or do they?

推荐答案

你失去了一些东西。 ;)还有就是你应该处理多一个操作类型: ACTION_CANCEL ACTION_CANCEL 时,正在进行的手势中止在一些更高级别的发送 - 一些更高级别的组件可能截获手势,并采取过来,等

You're missing something. ;) There is one more action type that you should handle: ACTION_CANCEL. ACTION_CANCEL is sent when the gesture in progress is aborted at some higher level - some higher-level component may have intercepted the gesture and taken it over, etc.

这篇关于Android的多点触控:ACTION_UP并不总是叫什么名字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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