的getAction()仅给出ACTION_DOWN [英] getAction() gives only ACTION_DOWN

查看:128
本文介绍了的getAction()仅给出ACTION_DOWN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关我写一个应用程序,我想调用某个动作一旦用户抬起手指离开屏幕。我明白我需要检查是否event.getAction()是ACTION_UP,但我来自的getAction得到()是ACTION_DOWN。我的code是这样的:

For an application I am writing, I want to invoke a certain action once the user lifted his finger off the screen. I understood I need to check if event.getAction() is ACTION_UP, but all I get from getAction() is ACTION_DOWN. My code looks like this:

menu = new MenuView(this);
        menu.setBackgroundColor(Color.WHITE);
        menu.setKeepScreenOn(true);
...
setContentView(menu);
 menu.requestFocus();
...
public class MenuView extends View
{
...
public MenuView(Context context) 
    {
        super(context);
        setFocusable(true);
    }

任何人都知道什么是问题的原因?

Anybody knows what is the reason for the problem?

感谢你在前进。

推荐答案

请它告诉你的监听器处理的触摸事件的操作系统肯定onTouch返回true。

make sure onTouch returns true which tells the os your listener handles the touch event.

从文档:onTouch() - 这将返回一个布尔值,表明你的听众是否消耗了本次活动。最重要的是,这个事件可以有相互跟随的多个动作。所以,如果你返回false收到向下动作事件时,即表示您还没有消耗的情况下,也是不感兴趣,从这个事件的后续行动。因此,你将不会被调用的事件内的任何其他操作,如手指的手势,或最终的后续行动的事件。

from the docs: onTouch() - This returns a boolean to indicate whether your listener consumes this event. The important thing is that this event can have multiple actions that follow each other. So, if you return false when the down action event is received, you indicate that you have not consumed the event and are also not interested in subsequent actions from this event. Thus, you will not be called for any other actions within the event, such as a finger gesture, or the eventual up action event.

<一个href="http://developer.android.com/reference/android/view/View.html#onTouchEvent%28android.view.MotionEvent%29">http://developer.android.com/reference/android/view/View.html#onTouchEvent%28android.view.MotionEvent%29

这篇关于的getAction()仅给出ACTION_DOWN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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