click事件的顺序由父视图和子视图处理 [英] The order of click event handled by parent view and child view

查看:375
本文介绍了click事件的顺序由父视图和子视图处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直对Android开发了一段时间,但我仍然感到困惑这个问题。

I have been working on android development for a while, but I am still confused about this question..

从Android文档称,该事件将会从根视图开始,并分派到子视图。
这意味着视图之前的ViewGroup应该得到触摸事件(这是它的孩子),但是从我的调试,这是不是这样的...

From android documentation said, the event will start from root view, and dispatched to the child view. Which means viewgroup should get touch event before view(which is its child), but from what I have debugged, this is not the case...

我创建了一个RadioGroup中,则每次增加三个单选按钮进去,当我点击单选按钮,就会触发其Click事件。 radioGroup中的单击事件不会甚至被解雇......

I create a RadioGroup, then add three radiobutton into it, every time when I click radiobutton, its click event is triggered. Radiogroup's click event is not even fired...

我们如何解释呢?

你知道吗?谢谢你。

推荐答案

当一个孩子处理的onClick,父不接收该事件。如果你想看到父母拿到的情况下,不设置对孩子的onClickListener。

When a child handles the onClick, the parent does not receive the event. If you want to see the parent get the event, don't set an onClickListener on the child.

onTouch事件的处理方式稍有不同。

onTouch events are handled a bit differently.

这篇关于click事件的顺序由父视图和子视图处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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