如何Android的触摸事件发表?事件、Android

由网友(康忙北鼻。)分享简介:我不问如何处理触摸事件,但到底是怎么回事幕后?如果有多个嵌套小部件,为了什么?他们看到的事件?请问开发商有过任何控制?理想情况下,我想关于这个问题的文件。I'm not asking how to handle touch events, but what is going on behind the scenes?...

我不问如何处理触摸事件,但到底是怎么回事幕后?如果有多个嵌套小部件,为了什么?他们看到的事件?请问开发商有过任何控制?理想情况下,我想关于这个问题的文件。

I'm not asking how to handle touch events, but what is going on behind the scenes? If there are several nested widgets, what order do they see the events in? Does the developer have any control over it? Ideally I would like a document on the subject.

推荐答案

从活动的观点:

触摸事件首先被传递到Activity.dispatchTouchEvent。这就是你可能首先抓住他们。

Touch events are delivered first to Activity.dispatchTouchEvent. It's where you may catch them first.

在这里,他们得到分赴窗口,在那里他们遍历视图层次,在这样的顺序被最后绘制的(其他部件的顶部)窗口有机会处理触摸View.onTouchEvent第一。如果某些观的onTouchEvent返回true,则遍历停止和其他视图不接受触摸事件。

Here they get dispatched to Window, where they traverse View hierarchy, in such order that Widgets that are drawn last (on top of other widgets) have chance to process touch in View.onTouchEvent first. If some View returns true in onTouchEvent, then traversal stops and other Views don't receive touch event.

最后,如果没有查看消耗触摸,它交付给Activity.onTouchEvent。

Finally, if no View consumes touch, it's delivered to Activity.onTouchEvent.

这就是你的控制。而且它是合乎逻辑的,你看到的画在别的上面,什么都有机会抽取的东西它下面的前处理触摸事件。

That's all your control. And it's logical that what you see drawn on top of something else, has chance to process touch event before something drawn below it.

阅读全文

相关推荐

最新文章