Android的:不能看到ACTION_MOVE /在一个RelativeLayout的中的onTouchEvent [英] Android: can't see ACTION_MOVE/UP in onTouchEvent of a RelativeLayout

查看:122
本文介绍了Android的:不能看到ACTION_MOVE /在一个RelativeLayout的中的onTouchEvent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注册的侦听器RelativeLayout的,见下文。我想补充一些自定义事件处理,

I registered a listener to a RelativeLayout, see below. I'd like to add some custom event handling,

mOnTouchListener = new OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            final int action = motionEvent.getAction();
            boolean ret = false;

            switch (action) {
            case MotionEvent.ACTION_DOWN:
                ret = doSth(motionEvent);
                break;
            case MotionEvent.ACTION_MOVE:
                ret = doSth(motionEvent);
                break;
            case MotionEvent.ACTION_UP:
                ret = doSth(motionEvent);
                break;
            }

            return ret;     // returning false got me none of MOVE/UP events right here
        }
    };

不过,我不能让任何移动/ UP事件,除非返回真。

However, I can't get any MOVE/UP events unless returned true.

另一次尝试,我注册了同一个侦听到一个CheckBox,一切都很好。
是否有一个ViewGroup和Widget之间的区别是什么?设计目的是什么?

Another try, I registered same listener to a CheckBox, everything went quite well.
Is there difference between ViewGroup and Widget? Design purpose?

推荐答案

不过,我不能让任何移动/ UP事件,除非回到真实的。

"However, I can't get any MOVE/UP events unless returned true."

您已经回答了你自己的问题。如果你不回,表明你很在乎和正在处理的情况下,系统不会给你以后的事件,因为你已经告诉系统你不不会在意它。如果你需要监控的触摸事件的整个生命周期,你需要回到总是

You've answered your own question. If you don't return true indicating that you care about and are handling the event, the system will not send you the subsequent events, because you've told the system you don't care about it. If you need to monitor the entire life cycle of the touch event, you need to return true always.

这篇关于Android的:不能看到ACTION_MOVE /在一个RelativeLayout的中的onTouchEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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