事件监听和事件派发流程
对于 onTouch 侦听器,该函数是
public boolean onTouch( View v, MotionEvent event )
基于我正在关注的教程,它指出返回 true - 我们已经处理了该事件; return false - View 本身将处理该事件
我无法真正理解这一点。
For onTouch listener, the function is
public boolean onTouch( View v, MotionEvent event )
based on the tutorial I'm following, it stated that return true - we have already processed the event ; return false - View itself will process the event
I can't really understand this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当视图位于其他视图之上时使用此功能。想象一下有一堆视图,如下所示:
因此用户将看到视图 A,然后视图 B 将位于其下方。如果视图 A 有一个 onTouch 侦听器,则只要该视图上发生触摸,就会调用它。如果返回 false,则触摸事件将传递给 View B,并且 View B 的 onTouch 监听器(如果有)可以去处理触摸事件。
这有道理吗?
This is used when there are Views on top of other Views. Imagine there are a stack of Views as follows:
So the user would see View A and then View B would be under it. If View A has an onTouch listener, it will get invoked whenever a touch occurs on that View. If false is returned, then the touch event will be passed to View B and View B's onTouch listener (if it has one), can then go and handle the touch event.
Does that make sense?