如何Android的触摸事件发表? [英] How are Android touch events delivered?

查看:151
本文介绍了如何Android的触摸事件发表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于如何Android的触摸事件发表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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