Skip to content

detail update #4

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

在Android中的View触摸事件处理主要涉及以下三个方法

- dispatchTouchEvent()
- onInterceptTouchEvent()
- onTouchEvent()
- dispatchTouchEvent(), 分发TouchEvent事件
- onInterceptTouchEvent(), 拦截TouchEvent事件
- onTouchEvent(), 处理TouchEvent事件

View的触摸事件传递,从前到后按照以下顺序
其中,onInterceptTouchEvent()方法在ViewGroup里,其他两个在View里。

View的触摸事件传递采用隧道方式,即从根元素依次往下传递,直到最内层子元素或在中间某一元素中由于某一条件停止传递,从前到后按照以下顺序

1. Activity
2. PhoneWindow
Expand Down Expand Up @@ -42,6 +44,8 @@ Android中默认认为View是消耗onTouchEvent()的,即返回值为true,除
#更多参考资料

- Android开发艺术探索-第三章 View的事件体系
- [Android触摸事件分发机制](http://hunankeda110.iteye.com/blog/1944311)
- [Gist: dispatchTouchEvent方法的源码解析](https://gist.github.com/Leaking/16e682b1ffac3a59c3df)

#关于我

Expand All @@ -51,4 +55,4 @@ Android中默认认为View是消耗onTouchEvent()的,即返回值为true,除
- 我的微博:[裸奔的凯子哥](http://weibo.com/zhaokaiqiang1992),每天会不定时分享高质量博客,欢迎关注
- 微信公众账号:kaizige1992

![](http://i12.tietuku.com/f55c34ddb1ba3830.jpg)
![](http://i12.tietuku.com/f55c34ddb1ba3830.jpg)