在onTouchEvent,ACTION_UP不起作用 [英] In onTouchEvent, ACTION_UP doesn't work
问题描述
我想,当一个球员触摸屏阅读,而当没有。
I'd like to read when a player touches the screen, and when not.
@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_UP){ //ACTION UP
actionOnUP = true;
Log.v("MC", "Up");
}
if(event.getAction() == 0){ //ACTION DOWN
actionOnUP = false;
Log.v("MC", "Down");
}
Log.v("MC", event.getAction() + " ");
return super.onTouchEvent(event);
}
这code,是的,它的工作原理,但只有当玩家触摸屏幕(ACTION_DOWN),但是当他不触摸屏幕(ACTION_UP),没有任何反应:/
This code, yes, it works, but only when player touch the screen (ACTION_DOWN), but when he don't touching the screen (ACTION_UP), nothing happens :/
^这是屏幕的形式LogCat中。你可以看到:这只是ACTION_DOWN,但没有约ACTION_UP。
类的扩展视图:
^ This is screen form LogCat. You can see: this is only ACTION_DOWN, but nothing about ACTION_UP. Class is extending View:
public class MainClass extends SurfaceView implements SurfaceHolder.Callback {
你能帮助我吗?
编辑:我的游戏是基于本教程:<一href=\"http://www.droidnova.com/2d-tutorial-series-part-v,848.html\">http://www.droidnova.com/2d-tutorial-series-part-v,848.html
My game is based on this tutorial: http://www.droidnova.com/2d-tutorial-series-part-v,848.html
推荐答案
我的猜测是super.onTouchEvent正在返回假
,因为无论超你打电话没有按'在意的触摸事件。
My guess is that super.onTouchEvent is returning false
, as whatever superclass you're calling doesn't care about the touch event.
如果您返回假
来onTouchEvent,那么Android操作系统将不再通知你的手势任何进一步的事件。如果你想继续接收触摸事件信息( ACTION_UP
为例),那么你就必须返回真正
来第一个 ACTION_DOWN
事件。
If you return false
to onTouchEvent, then the Android OS will no longer notify you of any further events in that gesture. If you want to continue receiving touch event information (ACTION_UP
for example), then you must return true
to the first ACTION_DOWN
event.
这篇关于在onTouchEvent,ACTION_UP不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!