Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Event 事件传递机制 #4

Open
zhangsr opened this issue Nov 27, 2015 · 0 comments
Open

Android Event 事件传递机制 #4

zhangsr opened this issue Nov 27, 2015 · 0 comments

Comments

@zhangsr
Copy link
Owner

zhangsr commented Nov 27, 2015

原理流程图:

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 系列

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant