简体   繁体   English

Android:在RelativeLayout的onTouchEvent中看不到ACTION_MOVE / UP

[英]Android: can't see ACTION_MOVE/UP in onTouchEvent of a RelativeLayout

I registered a listener to a RelativeLayout, see below. 我向RelativeLayout注册了一个监听器,见下文。 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
        }
    };

However, I can't get any MOVE/UP events unless returned true. 但是,除非返回true,否则我无法获得任何MOVE / UP事件。

Another try, I registered same listener to a CheckBox, everything went quite well. 另一个尝试,我向CheckBox注册了同样的监听器,一切都很顺利。
Is there difference between ViewGroup and Widget? ViewGroup和Widget之间有区别吗? Design purpose? 设计目的?

"However, I can't get any MOVE/UP events unless returned true." “但是,除非返回true,否则我无法获得任何MOVE / UP事件。”

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. 如果您没有返回true表示您关心并正在处理该事件,系统将不会向您发送后续事件,因为您告诉系统您不关心它。 If you need to monitor the entire life cycle of the touch event, you need to return true always. 如果您需要监视触摸事件的整个生命周期,则需要始终返回true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM