通过Demo测试Touch事件的传递
2018-02-15 本文已影响0人
Sejen27

如果以上所有View的onIntercept与onTouch都返回false(默认值)
Action | 传递 |
---|---|
Down | onIntercept(A) -> onInercept(B) -> onIntercept(C) -> onTouch(D) -> onTouch(C) -> onTouch(B) -> onTouch(A) -> 停止 |
没人处理Down事件,后续的Move,Up事件都不会传递下来
C的onIntercept返回true
- 如果C的onTouch返回false
Action | 传递 |
---|---|
Down | onIntercept(A) -> onInercept(B) -> onIntercept(C,true) -> onTouch(C) -> onTouch(B) -> onTouch(A) -> 停止 |
事件被C拦截,不会传递到D,由于还是没有人处理Down事件,后续的Move,Up事件还是不会传递下来
- 如果C的onTouch返回true
Action | 传递 |
---|---|
Down | onIntercept(A) -> onIntercept(B) -> onIntercept(C,true) -> onTouch(C,true) |
Move | [onIntercept(A) -> onIntercept(B) -> onTouch(C,true) -> 循环] |
Up | onIntercept(A) -> onIntercept(B) -> onTouch(C) |
- 如果C的onTouch返回true,且B的onIntercept在Move事件时返回true
Action | 传递 |
---|---|
Down | onIntercept(A) -> onIntercept(B) -> onIntercept(C,true) -> onTouch(C,true) |
Move | onIntercept(A) -> onIntercept(B,true) -> onTouch(C,Cancel) -> [onIntercept(A) -> onTouch(B) -> 循环] |
Up | onIntercept(A) -> onTouch(B) |
Move事件被B拦截,尽管B的onTouch返回false,因为C的onTouch已经返回true,所以事件不会再向上传给A
- 如果C的onTouch在Down时返回true,Move时返回false
Action | 传递 |
---|---|
Down | onIntercept(A) -> onIntercept(B) -> onIntercept(C,true) -> onTouch(C,true) |
Move | [onIntercept(A) -> onIntercept(B) -> onTouch(C) -> 循环] |
Up | onIntercept(A) -> onIntercept(B) -> onTouch(C) |
即使C的onTouch在Move事件时返回false,事件也不会再向上传递给B、A了