Android事件分发机制(Demo测试)


就是一个activity包含一个自定义linearlayout再嵌套一个view,分别都有不同的响应事件


一开始所有dispatch和on都置为super

点击view

12-17 05:27:02.530 5672-5672/com.example.eventdistribution I/xbh: activity消费了他
12-17 05:27:02.530 5672-5672/com.example.eventdistribution I/xbh: linear layout消费了他
12-17 05:27:02.530 5672-5672/com.example.eventdistribution I/xbh: view消费了他
12-17 05:27:02.530 5672-5672/com.example.eventdistribution I/xbh: view消费了他
12-17 05:27:02.530 5672-5672/com.example.eventdistribution I/xbh: linear layout消费了他
12-17 05:27:02.530 5672-5672/com.example.eventdistribution I/xbh: activity消费了他

点击linear layout

12-17 05:29:27.910 8139-8139/com.example.eventdistribution I/xbh: activity消费了他
12-17 05:29:27.910 8139-8139/com.example.eventdistribution I/xbh: linear layout消费了他
12-17 05:29:27.910 8139-8139/com.example.eventdistribution I/xbh: linear layout消费了他
12-17 05:29:27.910 8139-8139/com.example.eventdistribution I/xbh: activity消费了他


activity的dispatch置为true,false效果一样

点击view

12-17 05:28:04.846 6531-6531/com.example.eventdistribution I/xbh: activity消费了他

点击linear layout

12-17 05:29:59.745 8691-8691/com.example.eventdistribution I/xbh: activity消费了他


activity的on置为true,false效果一样

点击view

12-17 05:32:17.786 9807-9807/com.example.eventdistribution I/xbh: activity消费了他
12-17 05:32:17.786 9807-9807/com.example.eventdistribution I/xbh: linear layout消费了他
12-17 05:32:17.786 9807-9807/com.example.eventdistribution I/xbh: view消费了他
12-17 05:32:17.786 9807-9807/com.example.eventdistribution I/xbh: view消费了他
12-17 05:32:17.786 9807-9807/com.example.eventdistribution I/xbh: linear layout消费了他
12-17 05:32:17.786 9807-9807/com.example.eventdistribution I/xbh: activity消费了他

点击linear layout

12-17 05:32:38.727 9807-9807/com.example.eventdistribution I/xbh: activity消费了他
12-17 05:32:38.727 9807-9807/com.example.eventdistribution I/xbh: linear layout消费了他
12-17 05:32:38.727 9807-9807/com.example.eventdistribution I/xbh: linear layout消费了他
12-17 05:32:38.727 9807-9807/com.example.eventdistribution I/xbh: activity消费了他

这个是上篇文章图里没有的


此外button和textview用来做view的话,会大不一样。你在自定义他们的类中哪怕返回了super,接下来的DOWN事件也不会继续传播了。效果等同于返回true。此外你如果返回false,也不会继续向下传递。意思就是到了button的时候,不管在on中返回了什么,事件就到此为止了。

这是一个补充


其他都和上文的图中内容一样。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值