从 Android 中的事件处理方法返回的布尔值是什么意思 [英] What is meaning of boolean value returned from an event-handling method in Android

查看:32
本文介绍了从 Android 中的事件处理方法返回的布尔值是什么意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在android中,大多数事件监听器方法返回一个布尔值.这个真/假值是什么意思?它将对子序列事件产生什么影响?

In android, most event listener methods return a boolean value. What is that true/false value mean ? what will it result in to the subsequence events ?

class MyTouchListener implements OnTouchListener {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        logView.showEvent(event);
        return true;
    }
}

关于上面的例子,如果在onTouch方法中返回true,我发现每个触摸事件(DOWN、UP、MOVE等)都根据我的logView被捕获>.相反,如果返回false,则只有DOWN事件被捕获.所以似乎 return false 会阻止事件传播.我说得对吗?

Regarding to the above example, if return true in onTouch method,I found every touch event(DOWN,UP,MOVE,etc) has been captured according to my logView. On the contrary,if return false, onely the DOWN event been captured. So it's seemd that return false will prevent the event to propagate. Am I correct ?

此外,在 OnGestureListener 中,许多方法也必须返回一个布尔值.它们的含义相同吗?

Furthermore, in a OnGestureListener, many methods have to return a boolean value too. Do they have the same meaning ?

推荐答案

如果您从 ACTION_DOWN 事件返回 true,那么您对该事件中的其余事件感兴趣手势.在这种情况下,手势"表示直到最后的 ACTION_UPACTION_CANCEL 之前的所有事件.从 ACTION_DOWN 返回 false 意味着您不希望该事件,其他视图将有机会处理它.如果您有重叠视图,这可以是同级视图.如果不是,它将冒泡到父级.

If you return true from an ACTION_DOWN event you are interested in the rest of the events in that gesture. A "gesture" in this case means all events until the final ACTION_UP or ACTION_CANCEL. Returning false from an ACTION_DOWN means you do not want the event and other views will have the opportunity to handle it. If you have overlapping views this can be a sibling view. If not it will bubble up to the parent.

这篇关于从 Android 中的事件处理方法返回的布尔值是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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