从Android中的事件处理方法返回的布尔值是什么意思

2023-10-04移动开发问题
2

本文介绍了从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中的事件处理方法返回的布尔值是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

游戏中心 facebook 喜欢
Game center facebook like(游戏中心 facebook 喜欢)...
2024-08-12 移动开发问题
3

Cocos2d - 对 CCSprite 应用 GLImageProcessing 效果
Cocos2d - apply GLImageProcessing effect to CCSprite(Cocos2d - 对 CCSprite 应用 GLImageProcessing 效果)...
2024-08-12 移动开发问题
10

cocos2D iPhone中的UItextfield文本对齐问题
UItextfield text alignment issue in cocos2D iPhone(cocos2D iPhone中的UItextfield文本对齐问题)...
2024-08-12 移动开发问题
7

收到消息“警告:在正常情况下,_fillInQueueWithExtraSpace:.."和 MPMovieP
Got the message quot;WARNING: under normal conditions, _fillInQueueWithExtraSpace:..quot; and MPMoviePlayer rotation not work in iPad IOS 5.1(收到消息“警告:在正常情况下,_fillInQueueWithExtraSpace:..和 MPMoviePlayer 旋转在 iPad IOS 5.1 中...
2024-08-12 移动开发问题
6