Android的ACTION_UP甚至从来没有所谓的 [英] Android ACTION_UP even never called

查看:211
本文介绍了Android的ACTION_UP甚至从来没有所谓的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个小机器人跳和跑游戏,但我的问题是,我不能配置事件ACTION_UP权利。在这里,我的code:

I'm trying to make a small android Jump and Run game but my problem is that i can't configure the event ACTION_UP right. Here my Code:

public boolean onTouchEvent(MotionEvent event) {
    switch(event.getAction()){
    case MotionEvent.ACTION_DOWN:
        Log.d("OTE", "down"); 
        touchDownTrue = true;
        break;
    case MotionEvent.ACTION_UP:
        Log.d("OTE", "UP"); 
        touchDownTrue = false;
        break;
    }
}

的情况下MotionEvent.ACTION_UP不会被调用,我不知道为什么,如果我使用ACTION_CANCEL同样的情况。

the case MotionEvent.ACTION_UP is never called and i don't know why, the same happens if i use ACTION_CANCEL

推荐答案

我插入后返回super.onTouchEvent(事件);在方法结束(onTouchEvent必须返回值)的code为我工作,当我把它放在一个空白的主要活动。

After I insert return super.onTouchEvent(event); at the end of the method (onTouchEvent must return a value) your code works for me, when I put it in a blank main activity.

您或许应该返回真,而不是在这些情况下断裂了,因为你是响应事件。

You should probably return true instead of breaking in those cases because you are responding to the event.

这篇关于Android的ACTION_UP甚至从来没有所谓的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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