-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
原理流程图:
dispatchTouchEvent() 负责如何传递触摸事件
- 包括传递给onTouch() 还是 onTouchEvent()
- 标记DOWN的后续事件传递给哪个View
onInterceptTouchEvent() 负责如何拦截触摸事件
- 判断是否已经detach并拦截
- 判断是否开始滑动并拦截
onTouchEvent() 负责如何处理触摸事件
- 获取焦点
- 设置按下状态
- 调用onClick()
自定义View
| dispatchTouchEvent() | onInterceptTouchEvent() | onTouchEvent() | |
|---|---|---|---|
| SomeView | 不重写,用View的默认实现 | 无 | 重写 |
| SomeViewGroup | 一般不重写,用ViewGroup的默认实现 | 重写,默认返回false | (1)不重写,用View的默认实现如LinearLayout;(2)重写,如ListView |
常见问题
onTouch() vs onTouchEvent()
- 两者都用以处理触摸事件
- 前者给View的用户使用,后者是View自身的逻辑
- 前者先调用,如果消费了事件,不调用后者
参考
http://wangkuiwu.github.io/2015/01/01/TouchEvent-Introduce/ 系列
http://blog.csdn.net/guolin_blog/article/details/9097463 系列
Metadata
Metadata
Assignees
Labels
No labels
