click事件的顺序由父视图和子视图处理

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.