冯晓强,2013小品搞笑大全,美术教案
本次分享有一个非常重要的概念:view
,虽然说view
不属于四大组件,但是它的作用堪比四大组件,甚至比receiver和provider的重要性都要大。在android开发中,activity承担这可视化的功能,同时android系统提供了很多基础控件,常见的有button、textview、checkbox等。很多时候仅仅使用系统提供的控件是不能满足需求的,因此我们就需要能够根据需求进行新控件的定义,而控件的自定义就需要对android的view体系有深入的理解,只有这样才能写出完美的自定义控件。同时android手机属于移动设备,移动设备的一个特点就是用户可以直接通过屏幕来进行一系列操作,一个典型的场景就是屏幕的滑动,用户可以通过滑动来切换到不同的界面。很多情况下我们的应用都需要支持滑动操作,当处于不同层级的view都可以响应用户的滑动操作时,就会带来一个问题,那就是滑动冲突。如何解决滑动冲突呢?这对于初学者来说的确是个头疼的问题,其实解决滑动冲突本不难,它需要读者对view的事件分发机制有一定的了解,在这个基础上,我们就可以利于这个特性从而得出滑动冲突的解决方法。
——摘自android开发艺术探索
事件指的是什么呢?就是指用户触摸屏幕产生的
touch
事件;在android中它被封装成motionevent
。
motionevent
分类其余事件:
action_mask
、action_outside
、action_pointer_down
、
action_pointer_up
、action_hover_move
、action_scroll
、
action_hover_enter
、action_hover_exit
、action_button_press
、
action_button_release
、action_pointer_index_mask
、
action_pointer_index_shift
;有兴趣的可以下来自己了解。
经理分派任务,下属处理这个任务的过程。
view层次示例
view内部事件处理流程图:
流程1
:在activity#dispatchtouchevent返回false/true
当前流程是在activity#dispatchtouchevent
拦截并消费事件,不再往下传递
03-26 18:54:58.178 com.android.api23 i/com.android.api23.mainactivity: dispatchtouchevent#event:0
流程2
:在viewgroup#dispatchtouchevent返回true:
当前流程是viewgroup#dispatchtouchevent
拦截并消费事件,事件不再往下传递
03-26 19:08:23.268 com.android.api23 i/com.android.api23.mainactivity: dispatchtouchevent#event:0
03-26 19:08:23.268 com.android.api23 i/com.android.api23.myviewgroup: dispatchtouchevent#event:0
流程3
:在viewgroup#dispatchtouchevent返回false:
当前流程是停止往当前viewgroup
及其子view
事件,并将当前事件交由父类ontouchevent
处理。
03-26 19:09:15.238 com.android.api23 i/com.android.api23.mainactivity: dispatchtouchevent#event:0
03-26 19:09:15.238 com.android.api23 i/com.android.api23.myviewgroup: dispatchtouchevent#event:0
03-26 19:09:15.238 com.android.api23 i/com.android.api23.mainactivity: ontouchevent#event:0
流程4
:在viewgroup#onintercepttouchevent返回true:
03-26 19:07:02.918 com.android.api23 i/com.android.api23.mainactivity: dispatchtouchevent#event:0
03-26 19:07:02.918 com.android.api23 i/com.android.api23.myviewgroup: dispatchtouchevent#event:0
03-26 19:07:02.918 com.android.api23 i/com.android.api23.myviewgroup: onintercepttouchevent#event:0
03-26 19:07:02.918 com.android.api23 i/com.android.api23.myviewgroup: ontouchevent#event:0
03-26 19:07:02.918 com.android.api23 i/com.android.api23.mainactivity: ontouchevent#event:0
在viewgroup#onintercepttouchevent返回false
当前流程为系统默认流程即:viewgroup不拦截事件,事件将往下一级传递
03-26 19:06:11.008 com.android.api23 i/com.android.api23.mainactivity: dispatchtouchevent#event:0
03-26 19:06:11.018 com.android.api23 i/com.android.api23.myviewgroup: dispatchtouchevent#event:0
03-26 19:06:11.018 com.android.api23 i/com.android.api23.myviewgroup: onintercepttouchevent#event:0
03-26 19:06:11.018 com.android.api23 i/com.android.api23.myview: dispatchtouchevent#event:0
03-26 19:06:11.018 com.android.api23 i/com.android.api23.myview: ontouchevent#event:0
03-26 19:06:11.018 com.android.api23 i/com.android.api23.myviewgroup: ontouchevent#event:0
03-26 19:06:11.018 com.android.api23 i/com.android.api23.mainactivity: ontouchevent#event:0
流程5
:在view#dispatchtouchevent返回true:
当前流程是viewgroup#dispatchtouchevent
拦截并消费事件,事件不再往下传递
03-26 19:10:41.048 com.android.api23 i/com.android.api23.mainactivity: dispatchtouchevent#event:0
03-26 19:10:41.048 com.android.api23 i/com.android.api23.myviewgroup: dispatchtouchevent#event:0
03-26 19:10:41.048 com.android.api23 i/com.android.api23.myviewgroup: onintercepttouchevent#event:0
03-26 19:10:41.048 com.android.api23 i/com.android.api23.myview: dispatchtouchevent#event:0
流程6
:在view#dispatchtouchevent返回false:
03-26 19:11:36.458 com.android.api23 i/com.android.api23.mainactivity: dispatchtouchevent#event:0
03-26 19:11:36.458 com.android.api23 i/com.android.api23.myviewgroup: dispatchtouchevent#event:0
03-26 19:11:36.458 com.android.api23 i/com.android.api23.myviewgroup: onintercepttouchevent#event:0
03-26 19:11:36.458 com.android.api23 i/com.android.api23.myview: dispatchtouchevent#event:0
03-26 19:11:36.458 com.android.api23 i/com.android.api23.myviewgroup: ontouchevent#event:0
03-26 19:11:36.458 com.android.api23 i/com.android.api23.mainactivity: ontouchevent#event:0
流程7
:在view#ontouchevent返回true:
03-26 19:12:51.688 com.android.api23 i/com.android.api23.mainactivity: dispatchtouchevent#event:0
03-26 19:12:51.688 com.android.api23 i/com.android.api23.myviewgroup: dispatchtouchevent#event:0
03-26 19:12:51.688 com.android.api23 i/com.android.api23.myviewgroup: onintercepttouchevent#event:0
03-26 19:12:51.688 com.android.api23 i/com.android.api23.myview: dispatchtouchevent#event:0
03-26 19:12:51.688 com.android.api23 i/com.android.api23.myview: ontouchevent#event:0
在view#ontouchevent返回false:
当前流程为系统默认流程
03-26 19:13:58.188 com.android.api23 i/com.android.api23.mainactivity: dispatchtouchevent#event:0
03-26 19:13:58.188 com.android.api23 i/com.android.api23.myviewgroup: dispatchtouchevent#event:0
03-26 19:13:58.188 com.android.api23 i/com.android.api23.myviewgroup: onintercepttouchevent#event:0
03-26 19:13:58.188 com.android.api23 i/com.android.api23.myview: dispatchtouchevent#event:0
03-26 19:13:58.188 com.android.api23 i/com.android.api23.myview: ontouchevent#event:0
03-26 19:13:58.188 com.android.api23 i/com.android.api23.myviewgroup: ontouchevent#event:0
03-26 19:13:58.188 com.android.api23 i/com.android.api23.mainactivity: ontouchevent#event:0
流程8
:在viewgroup#ontouchevent返回true:
03-26 19:15:14.608 com.android.api23 i/com.android.api23.mainactivity: dispatchtouchevent#event:0
03-26 19:15:14.608 com.android.api23 i/com.android.api23.myviewgroup: dispatchtouchevent#event:0
03-26 19:15:14.608 com.android.api23 i/com.android.api23.myviewgroup: onintercepttouchevent#event:0
03-26 19:15:14.608 com.android.api23 i/com.android.api23.myview: dispatchtouchevent#event:0
03-26 19:15:14.608 com.android.api23 i/com.android.api23.myview: ontouchevent#event:0
03-26 19:15:14.608 com.android.api23 i/com.android.api23.myviewgroup: ontouchevent#event:0
在viewgroup#ontouchevent返回false:
当前流程为系统默认流程
03-26 19:16:48.928 com.android.api23 i/com.android.api23.mainactivity: dispatchtouchevent#event:0
03-26 19:16:48.928 com.android.api23 i/com.android.api23.myviewgroup: dispatchtouchevent#event:0
03-26 19:16:48.928 com.android.api23 i/com.android.api23.myviewgroup: onintercepttouchevent#event:0
03-26 19:16:48.928 com.android.api23 i/com.android.api23.myview: dispatchtouchevent#event:0
03-26 19:16:48.928 com.android.api23 i/com.android.api23.myview: ontouchevent#event:0
03-26 19:16:48.928 com.android.api23 i/com.android.api23.myviewgroup: ontouchevent#event:0
03-26 19:16:48.928 com.android.api23 i/com.android.api23.mainactivity: ontouchevent#event:0
流程9
:在activity#ontouchevent返回true:
03-26 19:18:49.648 com.android.api23 i/com.android.api23.mainactivity: dispatchtouchevent#event:0
03-26 19:18:49.648 com.android.api23 i/com.android.api23.myviewgroup: dispatchtouchevent#event:0
03-26 19:18:49.648 com.android.api23 i/com.android.api23.myviewgroup: onintercepttouchevent#event:0
03-26 19:18:49.648 com.android.api23 i/com.android.api23.myview: dispatchtouchevent#event:0
03-26 19:18:49.648 com.android.api23 i/com.android.api23.myview: ontouchevent#event:0
03-26 19:18:49.648 com.android.api23 i/com.android.api23.myviewgroup: ontouchevent#event:0
03-26 19:18:49.648 com.android.api23 i/com.android.api23.mainactivity: ontouchevent#event:0
在activity#ontouchevent返回false:
当前流程为系统默认流程
03-26 19:20:07.738 com.android.api23 i/com.android.api23.mainactivity: dispatchtouchevent#event:0
03-26 19:20:07.738 com.android.api23 i/com.android.api23.myviewgroup: dispatchtouchevent#event:0
03-26 19:20:07.738 com.android.api23 i/com.android.api23.myviewgroup: onintercepttouchevent#event:0
03-26 19:20:07.738 com.android.api23 i/com.android.api23.myview: dispatchtouchevent#event:0
03-26 19:20:07.738 com.android.api23 i/com.android.api23.myview: ontouchevent#event:0
03-26 19:20:07.738 com.android.api23 i/com.android.api23.myviewgroup: ontouchevent#event:0
03-26 19:20:07.738 com.android.api23 i/com.android.api23.mainactivity: ontouchevent#event:0
androidapi23:android事件分发机制测试demo
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Android apk 项目一键打包并上传到蒲公英的实现方法
Android 自定义LineLayout实现满屏任意拖动功能的示例代码
android 限制某个操作每天只能操作指定的次数(示例代码详解)
Android 集成 google 登录并获取性别等隐私信息的实现代码
网友评论