什么是布尔值的含义从Android的事件处理方法返回含义、事件、方法、布尔值

2023-09-12 07:03:48 作者:伱的世界ˊ我如何介入°

在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 方式,我发现每一个触摸事件(向下,向上,移动等),根据我的日志查看。相反,如果返回FALSE,onely向下事件被抓获。因此,它的seemd返回false将prevent事件传播。我是正确?

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 你感兴趣的事件在该动作的事件的其余部分。在这种情况下的姿态是指所有事件,直到最后的 ACTION_UP ACTION_CANCEL 。返回 ACTION_DOWN 表示不希望事件和其他视图将有机会来处理它。如果你有重叠的看法这可能是一个同级视图。如果不是会冒泡到父。

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.