事件分发


参考:

  • Android事件分发机制完全解析,带你从源码的角度彻底理解(上)
  • Android事件分发机制完全解析,带你从源码的角度彻底理解(下)
  • Android事件分发机制详解:史上最全面、最易懂
  • 图解 Android 事件分发机制
  • Android全面解析之Window机制

文章目录

  • 事件分发
    • 一、流程概览
      • (1)总图
      • (2)一个事例
        • 从点击`Button`开始的事件分发流程如下:
        • 从点击`Buttton`开始的事件消费情况如下:
    • 二、dispatchTouchEvent
      • 1. Activity.dispatchTouchEvent
          • Activity.dispatchTouchEvent流程图
          • Activity.dispatchTouchEvent中涉及到的部分变量的类图
        • (1)onUserInteraction和onUserLeaveHint
        • (2)PhoneWindow
        • (3)返回值
      • 2. ViewGroup.dispatchTouchEvent
        • onInterceptTouchEvent
      • 3. View.dispatchTouchEvent
        • (1)ViewGroup调用super.dispatchTouchEvent
        • (2)View调用dispatchTouchEvent
    • 三、总结

本文贴出的代码有删减!


一、流程概览

(1)总图

从触摸某一个View的那一刻开始,事件分发流程如下:

#mermaid-svg-A9rtNQpwLdTNGDuT .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-A9rtNQpwLdTNGDuT .label text{fill:#333}#mermaid-svg-A9rtNQpwLdTNGDuT .node rect,#mermaid-svg-A9rtNQpwLdTNGDuT .node circle,#mermaid-svg-A9rtNQpwLdTNGDuT .node ellipse,#mermaid-svg-A9rtNQpwLdTNGDuT .node polygon,#mermaid-svg-A9rtNQpwLdTNGDuT .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-A9rtNQpwLdTNGDuT .node .label{text-align:center;fill:#333}#mermaid-svg-A9rtNQpwLdTNGDuT .node.clickable{cursor:pointer}#mermaid-svg-A9rtNQpwLdTNGDuT .arrowheadPath{fill:#333}#mermaid-svg-A9rtNQpwLdTNGDuT .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-A9rtNQpwLdTNGDuT .flowchart-link{stroke:#333;fill:none}#mermaid-svg-A9rtNQpwLdTNGDuT .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-A9rtNQpwLdTNGDuT .edgeLabel rect{opacity:0.9}#mermaid-svg-A9rtNQpwLdTNGDuT .edgeLabel span{color:#333}#mermaid-svg-A9rtNQpwLdTNGDuT .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-A9rtNQpwLdTNGDuT .cluster text{fill:#333}#mermaid-svg-A9rtNQpwLdTNGDuT div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-A9rtNQpwLdTNGDuT .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-A9rtNQpwLdTNGDuT text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-A9rtNQpwLdTNGDuT .actor-line{stroke:grey}#mermaid-svg-A9rtNQpwLdTNGDuT .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-A9rtNQpwLdTNGDuT .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-A9rtNQpwLdTNGDuT #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-A9rtNQpwLdTNGDuT .sequenceNumber{fill:#fff}#mermaid-svg-A9rtNQpwLdTNGDuT #sequencenumber{fill:#333}#mermaid-svg-A9rtNQpwLdTNGDuT #crosshead path{fill:#333;stroke:#333}#mermaid-svg-A9rtNQpwLdTNGDuT .messageText{fill:#333;stroke:#333}#mermaid-svg-A9rtNQpwLdTNGDuT .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-A9rtNQpwLdTNGDuT .labelText,#mermaid-svg-A9rtNQpwLdTNGDuT .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-A9rtNQpwLdTNGDuT .loopText,#mermaid-svg-A9rtNQpwLdTNGDuT .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-A9rtNQpwLdTNGDuT .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-A9rtNQpwLdTNGDuT .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-A9rtNQpwLdTNGDuT .noteText,#mermaid-svg-A9rtNQpwLdTNGDuT .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-A9rtNQpwLdTNGDuT .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-A9rtNQpwLdTNGDuT .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-A9rtNQpwLdTNGDuT .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-A9rtNQpwLdTNGDuT .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-A9rtNQpwLdTNGDuT .section{stroke:none;opacity:0.2}#mermaid-svg-A9rtNQpwLdTNGDuT .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-A9rtNQpwLdTNGDuT .section2{fill:#fff400}#mermaid-svg-A9rtNQpwLdTNGDuT .section1,#mermaid-svg-A9rtNQpwLdTNGDuT .section3{fill:#fff;opacity:0.2}#mermaid-svg-A9rtNQpwLdTNGDuT .sectionTitle0{fill:#333}#mermaid-svg-A9rtNQpwLdTNGDuT .sectionTitle1{fill:#333}#mermaid-svg-A9rtNQpwLdTNGDuT .sectionTitle2{fill:#333}#mermaid-svg-A9rtNQpwLdTNGDuT .sectionTitle3{fill:#333}#mermaid-svg-A9rtNQpwLdTNGDuT .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-A9rtNQpwLdTNGDuT .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-A9rtNQpwLdTNGDuT .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-A9rtNQpwLdTNGDuT .grid path{stroke-width:0}#mermaid-svg-A9rtNQpwLdTNGDuT .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-A9rtNQpwLdTNGDuT .task{stroke-width:2}#mermaid-svg-A9rtNQpwLdTNGDuT .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-A9rtNQpwLdTNGDuT .taskText:not([font-size]){font-size:11px}#mermaid-svg-A9rtNQpwLdTNGDuT .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-A9rtNQpwLdTNGDuT .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-A9rtNQpwLdTNGDuT .task.clickable{cursor:pointer}#mermaid-svg-A9rtNQpwLdTNGDuT .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-A9rtNQpwLdTNGDuT .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-A9rtNQpwLdTNGDuT .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-A9rtNQpwLdTNGDuT .taskText0,#mermaid-svg-A9rtNQpwLdTNGDuT .taskText1,#mermaid-svg-A9rtNQpwLdTNGDuT .taskText2,#mermaid-svg-A9rtNQpwLdTNGDuT .taskText3{fill:#fff}#mermaid-svg-A9rtNQpwLdTNGDuT .task0,#mermaid-svg-A9rtNQpwLdTNGDuT .task1,#mermaid-svg-A9rtNQpwLdTNGDuT .task2,#mermaid-svg-A9rtNQpwLdTNGDuT .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-A9rtNQpwLdTNGDuT .taskTextOutside0,#mermaid-svg-A9rtNQpwLdTNGDuT .taskTextOutside2{fill:#000}#mermaid-svg-A9rtNQpwLdTNGDuT .taskTextOutside1,#mermaid-svg-A9rtNQpwLdTNGDuT .taskTextOutside3{fill:#000}#mermaid-svg-A9rtNQpwLdTNGDuT .active0,#mermaid-svg-A9rtNQpwLdTNGDuT .active1,#mermaid-svg-A9rtNQpwLdTNGDuT .active2,#mermaid-svg-A9rtNQpwLdTNGDuT .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-A9rtNQpwLdTNGDuT .activeText0,#mermaid-svg-A9rtNQpwLdTNGDuT .activeText1,#mermaid-svg-A9rtNQpwLdTNGDuT .activeText2,#mermaid-svg-A9rtNQpwLdTNGDuT .activeText3{fill:#000 !important}#mermaid-svg-A9rtNQpwLdTNGDuT .done0,#mermaid-svg-A9rtNQpwLdTNGDuT .done1,#mermaid-svg-A9rtNQpwLdTNGDuT .done2,#mermaid-svg-A9rtNQpwLdTNGDuT .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-A9rtNQpwLdTNGDuT .doneText0,#mermaid-svg-A9rtNQpwLdTNGDuT .doneText1,#mermaid-svg-A9rtNQpwLdTNGDuT .doneText2,#mermaid-svg-A9rtNQpwLdTNGDuT .doneText3{fill:#000 !important}#mermaid-svg-A9rtNQpwLdTNGDuT .crit0,#mermaid-svg-A9rtNQpwLdTNGDuT .crit1,#mermaid-svg-A9rtNQpwLdTNGDuT .crit2,#mermaid-svg-A9rtNQpwLdTNGDuT .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-A9rtNQpwLdTNGDuT .activeCrit0,#mermaid-svg-A9rtNQpwLdTNGDuT .activeCrit1,#mermaid-svg-A9rtNQpwLdTNGDuT .activeCrit2,#mermaid-svg-A9rtNQpwLdTNGDuT .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-A9rtNQpwLdTNGDuT .doneCrit0,#mermaid-svg-A9rtNQpwLdTNGDuT .doneCrit1,#mermaid-svg-A9rtNQpwLdTNGDuT .doneCrit2,#mermaid-svg-A9rtNQpwLdTNGDuT .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-A9rtNQpwLdTNGDuT .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-A9rtNQpwLdTNGDuT .milestoneText{font-style:italic}#mermaid-svg-A9rtNQpwLdTNGDuT .doneCritText0,#mermaid-svg-A9rtNQpwLdTNGDuT .doneCritText1,#mermaid-svg-A9rtNQpwLdTNGDuT .doneCritText2,#mermaid-svg-A9rtNQpwLdTNGDuT .doneCritText3{fill:#000 !important}#mermaid-svg-A9rtNQpwLdTNGDuT .activeCritText0,#mermaid-svg-A9rtNQpwLdTNGDuT .activeCritText1,#mermaid-svg-A9rtNQpwLdTNGDuT .activeCritText2,#mermaid-svg-A9rtNQpwLdTNGDuT .activeCritText3{fill:#000 !important}#mermaid-svg-A9rtNQpwLdTNGDuT .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-A9rtNQpwLdTNGDuT g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-A9rtNQpwLdTNGDuT g.classGroup text .title{font-weight:bolder}#mermaid-svg-A9rtNQpwLdTNGDuT g.clickable{cursor:pointer}#mermaid-svg-A9rtNQpwLdTNGDuT g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-A9rtNQpwLdTNGDuT g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-A9rtNQpwLdTNGDuT .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-A9rtNQpwLdTNGDuT .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-A9rtNQpwLdTNGDuT .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-A9rtNQpwLdTNGDuT .dashed-line{stroke-dasharray:3}#mermaid-svg-A9rtNQpwLdTNGDuT #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-A9rtNQpwLdTNGDuT #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-A9rtNQpwLdTNGDuT #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-A9rtNQpwLdTNGDuT #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-A9rtNQpwLdTNGDuT #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-A9rtNQpwLdTNGDuT #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-A9rtNQpwLdTNGDuT #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-A9rtNQpwLdTNGDuT #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-A9rtNQpwLdTNGDuT .commit-id,#mermaid-svg-A9rtNQpwLdTNGDuT .commit-msg,#mermaid-svg-A9rtNQpwLdTNGDuT .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-A9rtNQpwLdTNGDuT .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-A9rtNQpwLdTNGDuT .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-A9rtNQpwLdTNGDuT g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-A9rtNQpwLdTNGDuT g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-A9rtNQpwLdTNGDuT g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-A9rtNQpwLdTNGDuT g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-A9rtNQpwLdTNGDuT g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-A9rtNQpwLdTNGDuT g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-A9rtNQpwLdTNGDuT .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-A9rtNQpwLdTNGDuT .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-A9rtNQpwLdTNGDuT .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-A9rtNQpwLdTNGDuT .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-A9rtNQpwLdTNGDuT .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-A9rtNQpwLdTNGDuT .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-A9rtNQpwLdTNGDuT .edgeLabel text{fill:#333}#mermaid-svg-A9rtNQpwLdTNGDuT .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-A9rtNQpwLdTNGDuT .node circle.state-start{fill:black;stroke:black}#mermaid-svg-A9rtNQpwLdTNGDuT .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-A9rtNQpwLdTNGDuT #statediagram-barbEnd{fill:#9370db}#mermaid-svg-A9rtNQpwLdTNGDuT .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-A9rtNQpwLdTNGDuT .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-A9rtNQpwLdTNGDuT .statediagram-state .divider{stroke:#9370db}#mermaid-svg-A9rtNQpwLdTNGDuT .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-A9rtNQpwLdTNGDuT .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-A9rtNQpwLdTNGDuT .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-A9rtNQpwLdTNGDuT .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-A9rtNQpwLdTNGDuT .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-A9rtNQpwLdTNGDuT .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-A9rtNQpwLdTNGDuT .note-edge{stroke-dasharray:5}#mermaid-svg-A9rtNQpwLdTNGDuT .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-A9rtNQpwLdTNGDuT .error-icon{fill:#522}#mermaid-svg-A9rtNQpwLdTNGDuT .error-text{fill:#522;stroke:#522}#mermaid-svg-A9rtNQpwLdTNGDuT .edge-thickness-normal{stroke-width:2px}#mermaid-svg-A9rtNQpwLdTNGDuT .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-A9rtNQpwLdTNGDuT .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-A9rtNQpwLdTNGDuT .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-A9rtNQpwLdTNGDuT .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-A9rtNQpwLdTNGDuT .marker{fill:#333}#mermaid-svg-A9rtNQpwLdTNGDuT .marker.cross{stroke:#333}:root { --mermaid-font-family: "trebuchet ms", verdana, arial;} #mermaid-svg-A9rtNQpwLdTNGDuT .blackWhite > * { fill:#000 !important; color:#fff !important; stroke:#000 !important; font-weight:bold !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .blackWhite tspan { fill:#fff !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .blueWhite > * { fill:#009cff !important; color:#fff !important; stroke:#009cff !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .blueWhite tspan { fill:#fff !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .con > * { fill:#008000 !important; color:#fff !important; stroke:#008000 !important; font-weight:bold !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .con tspan { fill:#fff !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .unCon > * { fill:#ff0000 !important; color:#fff !important; stroke:#ff0000 !important; font-weight:bold !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .unCon tspan { fill:#fff !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .con2 > * { fill:#32CD32 !important; color:#fff !important; stroke:#32CD32 !important; font-weight:bold !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .con2 tspan { fill:#fff !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .unCon2 > * { fill:#ff0000 !important; color:#fff !important; stroke:#ff0000 !important; font-weight:bold !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .unCon2 tspan { fill:#fff !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .con3 > * { fill:#2E8B57 !important; color:#fff !important; stroke:#2E8B57 !important; font-weight:bold !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .con3 tspan { fill:#fff !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .unCon3 > * { fill:#FF4500 !important; color:#fff !important; stroke:#FF4500 !important; font-weight:bold !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .unCon3 tspan { fill:#fff !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .pro > * { fill:#FFA500 !important; color:#fff !important; stroke:#FFA500 !important; font-weight:bold !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .pro tspan { fill:#fff !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .res > * { fill:#800080 !important; color:#fff !important; stroke:#800080 !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .res tspan { fill:#fff !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .inter > * { fill:#00CED1 !important; color:#000 !important; stroke:#00CED1 !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .inter tspan { fill:#000 !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .blueWhite2 > * { fill:#4169E1 !important; color:#fff !important; stroke:#4169E1 !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .blueWhite2 tspan { fill:#fff !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .blueWhite3 > * { fill:#483D8B !important; color:#fff !important; stroke:#483D8B !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .blueWhite3 tspan { fill:#fff !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .pro2 > * { fill:#CD853F !important; color:#fff !important; stroke:#CD853F !important; font-weight:bold !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .pro2 tspan { fill:#fff !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .pro3 > * { fill:#8B4513 !important; color:#fff !important; stroke:#8B4513 !important; font-weight:bold !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .pro3 tspan { fill:#fff !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .res2 > * { fill: #8A2BE2 !important; color:#fff !important; stroke:#8A2BE2 !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .res2 tspan { fill:#fff !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .res3 > * { fill: #BA55D3 !important; color:#fff !important; stroke:#BA55D3 !important; } #mermaid-svg-A9rtNQpwLdTNGDuT .res3 tspan { fill:#fff !important; } #mermaid-svg-A9rtNQpwLdTNGDuT {color: rgba(0, 0, 0, 0.75);font: ;}

View
dispatchTouchEvent
onTouchEvent
ViewGroup
dispatchTouchEvent
onTouchEvent
Activity
dispatchTouchEvent
onTouchEvent
true
false
true
false
PhoneWindow.superDispatchTouchEvent
true
false
返回值
返回值
返回值
结束
执行
开始
执行
开始
事件已消费
结果
事件未消费
结束
执行
开始
onInterceptTouchEvent
执行
开始
事件已消费
结果
事件未消费
结束
执行
开始
执行
开始
事件已消费
结果
开始
结束

说明

  1. onTouchEvent就是直接处理触摸事件时调用的方法,跟它比较相似的OnTouchListener.onTouch则是在View接收到触摸事件之前调用的,即优先级高于onTouchEvent
  2. onInterceptTouchEvent是指是否要拦截当前的事件,值得注意的是只有ViewGroup才有这个方法,ActivityView都没有。这个方法的返回值如果是TRUE,那么就表示当前ViewGroup要自己处理这个事件,不再将事件传给后续的子View。默认返回FALSE
  3. dispatchTouchEvent就是事件分发,如果返回TRUE,那就是当前事件被消费了,不会再往下分发。onInterceptTouchEvent在就是在该方法内执行的。通过先确定当前事件没有有被CANCELINTERCEPT,才会继续dispatch。

(2)一个事例

假设有一个Activity,它的布局是一个LinearLayout,中间有一个Button

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><Buttonandroid:layout_width="180dp"android:layout_height="180dp"android:text="hello"android:textSize="22sp"android:gravity="center" />
</LinearLayout>

从点击Button开始的事件分发流程如下:

#mermaid-svg-11oPS3mNrsYbJZoI .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-11oPS3mNrsYbJZoI .label text{fill:#333}#mermaid-svg-11oPS3mNrsYbJZoI .node rect,#mermaid-svg-11oPS3mNrsYbJZoI .node circle,#mermaid-svg-11oPS3mNrsYbJZoI .node ellipse,#mermaid-svg-11oPS3mNrsYbJZoI .node polygon,#mermaid-svg-11oPS3mNrsYbJZoI .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-11oPS3mNrsYbJZoI .node .label{text-align:center;fill:#333}#mermaid-svg-11oPS3mNrsYbJZoI .node.clickable{cursor:pointer}#mermaid-svg-11oPS3mNrsYbJZoI .arrowheadPath{fill:#333}#mermaid-svg-11oPS3mNrsYbJZoI .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-11oPS3mNrsYbJZoI .flowchart-link{stroke:#333;fill:none}#mermaid-svg-11oPS3mNrsYbJZoI .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-11oPS3mNrsYbJZoI .edgeLabel rect{opacity:0.9}#mermaid-svg-11oPS3mNrsYbJZoI .edgeLabel span{color:#333}#mermaid-svg-11oPS3mNrsYbJZoI .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-11oPS3mNrsYbJZoI .cluster text{fill:#333}#mermaid-svg-11oPS3mNrsYbJZoI div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-11oPS3mNrsYbJZoI .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-11oPS3mNrsYbJZoI text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-11oPS3mNrsYbJZoI .actor-line{stroke:grey}#mermaid-svg-11oPS3mNrsYbJZoI .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-11oPS3mNrsYbJZoI .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-11oPS3mNrsYbJZoI #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-11oPS3mNrsYbJZoI .sequenceNumber{fill:#fff}#mermaid-svg-11oPS3mNrsYbJZoI #sequencenumber{fill:#333}#mermaid-svg-11oPS3mNrsYbJZoI #crosshead path{fill:#333;stroke:#333}#mermaid-svg-11oPS3mNrsYbJZoI .messageText{fill:#333;stroke:#333}#mermaid-svg-11oPS3mNrsYbJZoI .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-11oPS3mNrsYbJZoI .labelText,#mermaid-svg-11oPS3mNrsYbJZoI .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-11oPS3mNrsYbJZoI .loopText,#mermaid-svg-11oPS3mNrsYbJZoI .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-11oPS3mNrsYbJZoI .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-11oPS3mNrsYbJZoI .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-11oPS3mNrsYbJZoI .noteText,#mermaid-svg-11oPS3mNrsYbJZoI .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-11oPS3mNrsYbJZoI .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-11oPS3mNrsYbJZoI .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-11oPS3mNrsYbJZoI .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-11oPS3mNrsYbJZoI .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-11oPS3mNrsYbJZoI .section{stroke:none;opacity:0.2}#mermaid-svg-11oPS3mNrsYbJZoI .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-11oPS3mNrsYbJZoI .section2{fill:#fff400}#mermaid-svg-11oPS3mNrsYbJZoI .section1,#mermaid-svg-11oPS3mNrsYbJZoI .section3{fill:#fff;opacity:0.2}#mermaid-svg-11oPS3mNrsYbJZoI .sectionTitle0{fill:#333}#mermaid-svg-11oPS3mNrsYbJZoI .sectionTitle1{fill:#333}#mermaid-svg-11oPS3mNrsYbJZoI .sectionTitle2{fill:#333}#mermaid-svg-11oPS3mNrsYbJZoI .sectionTitle3{fill:#333}#mermaid-svg-11oPS3mNrsYbJZoI .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-11oPS3mNrsYbJZoI .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-11oPS3mNrsYbJZoI .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-11oPS3mNrsYbJZoI .grid path{stroke-width:0}#mermaid-svg-11oPS3mNrsYbJZoI .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-11oPS3mNrsYbJZoI .task{stroke-width:2}#mermaid-svg-11oPS3mNrsYbJZoI .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-11oPS3mNrsYbJZoI .taskText:not([font-size]){font-size:11px}#mermaid-svg-11oPS3mNrsYbJZoI .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-11oPS3mNrsYbJZoI .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-11oPS3mNrsYbJZoI .task.clickable{cursor:pointer}#mermaid-svg-11oPS3mNrsYbJZoI .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-11oPS3mNrsYbJZoI .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-11oPS3mNrsYbJZoI .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-11oPS3mNrsYbJZoI .taskText0,#mermaid-svg-11oPS3mNrsYbJZoI .taskText1,#mermaid-svg-11oPS3mNrsYbJZoI .taskText2,#mermaid-svg-11oPS3mNrsYbJZoI .taskText3{fill:#fff}#mermaid-svg-11oPS3mNrsYbJZoI .task0,#mermaid-svg-11oPS3mNrsYbJZoI .task1,#mermaid-svg-11oPS3mNrsYbJZoI .task2,#mermaid-svg-11oPS3mNrsYbJZoI .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-11oPS3mNrsYbJZoI .taskTextOutside0,#mermaid-svg-11oPS3mNrsYbJZoI .taskTextOutside2{fill:#000}#mermaid-svg-11oPS3mNrsYbJZoI .taskTextOutside1,#mermaid-svg-11oPS3mNrsYbJZoI .taskTextOutside3{fill:#000}#mermaid-svg-11oPS3mNrsYbJZoI .active0,#mermaid-svg-11oPS3mNrsYbJZoI .active1,#mermaid-svg-11oPS3mNrsYbJZoI .active2,#mermaid-svg-11oPS3mNrsYbJZoI .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-11oPS3mNrsYbJZoI .activeText0,#mermaid-svg-11oPS3mNrsYbJZoI .activeText1,#mermaid-svg-11oPS3mNrsYbJZoI .activeText2,#mermaid-svg-11oPS3mNrsYbJZoI .activeText3{fill:#000 !important}#mermaid-svg-11oPS3mNrsYbJZoI .done0,#mermaid-svg-11oPS3mNrsYbJZoI .done1,#mermaid-svg-11oPS3mNrsYbJZoI .done2,#mermaid-svg-11oPS3mNrsYbJZoI .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-11oPS3mNrsYbJZoI .doneText0,#mermaid-svg-11oPS3mNrsYbJZoI .doneText1,#mermaid-svg-11oPS3mNrsYbJZoI .doneText2,#mermaid-svg-11oPS3mNrsYbJZoI .doneText3{fill:#000 !important}#mermaid-svg-11oPS3mNrsYbJZoI .crit0,#mermaid-svg-11oPS3mNrsYbJZoI .crit1,#mermaid-svg-11oPS3mNrsYbJZoI .crit2,#mermaid-svg-11oPS3mNrsYbJZoI .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-11oPS3mNrsYbJZoI .activeCrit0,#mermaid-svg-11oPS3mNrsYbJZoI .activeCrit1,#mermaid-svg-11oPS3mNrsYbJZoI .activeCrit2,#mermaid-svg-11oPS3mNrsYbJZoI .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-11oPS3mNrsYbJZoI .doneCrit0,#mermaid-svg-11oPS3mNrsYbJZoI .doneCrit1,#mermaid-svg-11oPS3mNrsYbJZoI .doneCrit2,#mermaid-svg-11oPS3mNrsYbJZoI .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-11oPS3mNrsYbJZoI .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-11oPS3mNrsYbJZoI .milestoneText{font-style:italic}#mermaid-svg-11oPS3mNrsYbJZoI .doneCritText0,#mermaid-svg-11oPS3mNrsYbJZoI .doneCritText1,#mermaid-svg-11oPS3mNrsYbJZoI .doneCritText2,#mermaid-svg-11oPS3mNrsYbJZoI .doneCritText3{fill:#000 !important}#mermaid-svg-11oPS3mNrsYbJZoI .activeCritText0,#mermaid-svg-11oPS3mNrsYbJZoI .activeCritText1,#mermaid-svg-11oPS3mNrsYbJZoI .activeCritText2,#mermaid-svg-11oPS3mNrsYbJZoI .activeCritText3{fill:#000 !important}#mermaid-svg-11oPS3mNrsYbJZoI .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-11oPS3mNrsYbJZoI g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-11oPS3mNrsYbJZoI g.classGroup text .title{font-weight:bolder}#mermaid-svg-11oPS3mNrsYbJZoI g.clickable{cursor:pointer}#mermaid-svg-11oPS3mNrsYbJZoI g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-11oPS3mNrsYbJZoI g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-11oPS3mNrsYbJZoI .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-11oPS3mNrsYbJZoI .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-11oPS3mNrsYbJZoI .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-11oPS3mNrsYbJZoI .dashed-line{stroke-dasharray:3}#mermaid-svg-11oPS3mNrsYbJZoI #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-11oPS3mNrsYbJZoI #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-11oPS3mNrsYbJZoI #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-11oPS3mNrsYbJZoI #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-11oPS3mNrsYbJZoI #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-11oPS3mNrsYbJZoI #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-11oPS3mNrsYbJZoI #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-11oPS3mNrsYbJZoI #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-11oPS3mNrsYbJZoI .commit-id,#mermaid-svg-11oPS3mNrsYbJZoI .commit-msg,#mermaid-svg-11oPS3mNrsYbJZoI .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-11oPS3mNrsYbJZoI .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-11oPS3mNrsYbJZoI .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-11oPS3mNrsYbJZoI g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-11oPS3mNrsYbJZoI g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-11oPS3mNrsYbJZoI g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-11oPS3mNrsYbJZoI g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-11oPS3mNrsYbJZoI g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-11oPS3mNrsYbJZoI g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-11oPS3mNrsYbJZoI .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-11oPS3mNrsYbJZoI .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-11oPS3mNrsYbJZoI .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-11oPS3mNrsYbJZoI .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-11oPS3mNrsYbJZoI .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-11oPS3mNrsYbJZoI .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-11oPS3mNrsYbJZoI .edgeLabel text{fill:#333}#mermaid-svg-11oPS3mNrsYbJZoI .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-11oPS3mNrsYbJZoI .node circle.state-start{fill:black;stroke:black}#mermaid-svg-11oPS3mNrsYbJZoI .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-11oPS3mNrsYbJZoI #statediagram-barbEnd{fill:#9370db}#mermaid-svg-11oPS3mNrsYbJZoI .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-11oPS3mNrsYbJZoI .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-11oPS3mNrsYbJZoI .statediagram-state .divider{stroke:#9370db}#mermaid-svg-11oPS3mNrsYbJZoI .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-11oPS3mNrsYbJZoI .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-11oPS3mNrsYbJZoI .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-11oPS3mNrsYbJZoI .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-11oPS3mNrsYbJZoI .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-11oPS3mNrsYbJZoI .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-11oPS3mNrsYbJZoI .note-edge{stroke-dasharray:5}#mermaid-svg-11oPS3mNrsYbJZoI .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-11oPS3mNrsYbJZoI .error-icon{fill:#522}#mermaid-svg-11oPS3mNrsYbJZoI .error-text{fill:#522;stroke:#522}#mermaid-svg-11oPS3mNrsYbJZoI .edge-thickness-normal{stroke-width:2px}#mermaid-svg-11oPS3mNrsYbJZoI .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-11oPS3mNrsYbJZoI .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-11oPS3mNrsYbJZoI .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-11oPS3mNrsYbJZoI .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-11oPS3mNrsYbJZoI .marker{fill:#333}#mermaid-svg-11oPS3mNrsYbJZoI .marker.cross{stroke:#333}:root { --mermaid-font-family: "trebuchet ms", verdana, arial;} #mermaid-svg-11oPS3mNrsYbJZoI {color: rgba(0, 0, 0, 0.75);font: ;}

点击Button
Activity分发事件
PhoneWindow分发事件
LinearLayout分发事件
LinearLayout拦截事件
LinearLayout获得事件
分发结束
Button分发事件
Button获得事件

从点击Buttton开始的事件消费情况如下:

#mermaid-svg-E88mGHzEecyAznX1 .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-E88mGHzEecyAznX1 .label text{fill:#333}#mermaid-svg-E88mGHzEecyAznX1 .node rect,#mermaid-svg-E88mGHzEecyAznX1 .node circle,#mermaid-svg-E88mGHzEecyAznX1 .node ellipse,#mermaid-svg-E88mGHzEecyAznX1 .node polygon,#mermaid-svg-E88mGHzEecyAznX1 .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-E88mGHzEecyAznX1 .node .label{text-align:center;fill:#333}#mermaid-svg-E88mGHzEecyAznX1 .node.clickable{cursor:pointer}#mermaid-svg-E88mGHzEecyAznX1 .arrowheadPath{fill:#333}#mermaid-svg-E88mGHzEecyAznX1 .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-E88mGHzEecyAznX1 .flowchart-link{stroke:#333;fill:none}#mermaid-svg-E88mGHzEecyAznX1 .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-E88mGHzEecyAznX1 .edgeLabel rect{opacity:0.9}#mermaid-svg-E88mGHzEecyAznX1 .edgeLabel span{color:#333}#mermaid-svg-E88mGHzEecyAznX1 .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-E88mGHzEecyAznX1 .cluster text{fill:#333}#mermaid-svg-E88mGHzEecyAznX1 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-E88mGHzEecyAznX1 .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-E88mGHzEecyAznX1 text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-E88mGHzEecyAznX1 .actor-line{stroke:grey}#mermaid-svg-E88mGHzEecyAznX1 .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-E88mGHzEecyAznX1 .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-E88mGHzEecyAznX1 #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-E88mGHzEecyAznX1 .sequenceNumber{fill:#fff}#mermaid-svg-E88mGHzEecyAznX1 #sequencenumber{fill:#333}#mermaid-svg-E88mGHzEecyAznX1 #crosshead path{fill:#333;stroke:#333}#mermaid-svg-E88mGHzEecyAznX1 .messageText{fill:#333;stroke:#333}#mermaid-svg-E88mGHzEecyAznX1 .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-E88mGHzEecyAznX1 .labelText,#mermaid-svg-E88mGHzEecyAznX1 .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-E88mGHzEecyAznX1 .loopText,#mermaid-svg-E88mGHzEecyAznX1 .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-E88mGHzEecyAznX1 .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-E88mGHzEecyAznX1 .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-E88mGHzEecyAznX1 .noteText,#mermaid-svg-E88mGHzEecyAznX1 .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-E88mGHzEecyAznX1 .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-E88mGHzEecyAznX1 .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-E88mGHzEecyAznX1 .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-E88mGHzEecyAznX1 .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-E88mGHzEecyAznX1 .section{stroke:none;opacity:0.2}#mermaid-svg-E88mGHzEecyAznX1 .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-E88mGHzEecyAznX1 .section2{fill:#fff400}#mermaid-svg-E88mGHzEecyAznX1 .section1,#mermaid-svg-E88mGHzEecyAznX1 .section3{fill:#fff;opacity:0.2}#mermaid-svg-E88mGHzEecyAznX1 .sectionTitle0{fill:#333}#mermaid-svg-E88mGHzEecyAznX1 .sectionTitle1{fill:#333}#mermaid-svg-E88mGHzEecyAznX1 .sectionTitle2{fill:#333}#mermaid-svg-E88mGHzEecyAznX1 .sectionTitle3{fill:#333}#mermaid-svg-E88mGHzEecyAznX1 .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-E88mGHzEecyAznX1 .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-E88mGHzEecyAznX1 .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-E88mGHzEecyAznX1 .grid path{stroke-width:0}#mermaid-svg-E88mGHzEecyAznX1 .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-E88mGHzEecyAznX1 .task{stroke-width:2}#mermaid-svg-E88mGHzEecyAznX1 .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-E88mGHzEecyAznX1 .taskText:not([font-size]){font-size:11px}#mermaid-svg-E88mGHzEecyAznX1 .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-E88mGHzEecyAznX1 .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-E88mGHzEecyAznX1 .task.clickable{cursor:pointer}#mermaid-svg-E88mGHzEecyAznX1 .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-E88mGHzEecyAznX1 .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-E88mGHzEecyAznX1 .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-E88mGHzEecyAznX1 .taskText0,#mermaid-svg-E88mGHzEecyAznX1 .taskText1,#mermaid-svg-E88mGHzEecyAznX1 .taskText2,#mermaid-svg-E88mGHzEecyAznX1 .taskText3{fill:#fff}#mermaid-svg-E88mGHzEecyAznX1 .task0,#mermaid-svg-E88mGHzEecyAznX1 .task1,#mermaid-svg-E88mGHzEecyAznX1 .task2,#mermaid-svg-E88mGHzEecyAznX1 .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-E88mGHzEecyAznX1 .taskTextOutside0,#mermaid-svg-E88mGHzEecyAznX1 .taskTextOutside2{fill:#000}#mermaid-svg-E88mGHzEecyAznX1 .taskTextOutside1,#mermaid-svg-E88mGHzEecyAznX1 .taskTextOutside3{fill:#000}#mermaid-svg-E88mGHzEecyAznX1 .active0,#mermaid-svg-E88mGHzEecyAznX1 .active1,#mermaid-svg-E88mGHzEecyAznX1 .active2,#mermaid-svg-E88mGHzEecyAznX1 .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-E88mGHzEecyAznX1 .activeText0,#mermaid-svg-E88mGHzEecyAznX1 .activeText1,#mermaid-svg-E88mGHzEecyAznX1 .activeText2,#mermaid-svg-E88mGHzEecyAznX1 .activeText3{fill:#000 !important}#mermaid-svg-E88mGHzEecyAznX1 .done0,#mermaid-svg-E88mGHzEecyAznX1 .done1,#mermaid-svg-E88mGHzEecyAznX1 .done2,#mermaid-svg-E88mGHzEecyAznX1 .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-E88mGHzEecyAznX1 .doneText0,#mermaid-svg-E88mGHzEecyAznX1 .doneText1,#mermaid-svg-E88mGHzEecyAznX1 .doneText2,#mermaid-svg-E88mGHzEecyAznX1 .doneText3{fill:#000 !important}#mermaid-svg-E88mGHzEecyAznX1 .crit0,#mermaid-svg-E88mGHzEecyAznX1 .crit1,#mermaid-svg-E88mGHzEecyAznX1 .crit2,#mermaid-svg-E88mGHzEecyAznX1 .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-E88mGHzEecyAznX1 .activeCrit0,#mermaid-svg-E88mGHzEecyAznX1 .activeCrit1,#mermaid-svg-E88mGHzEecyAznX1 .activeCrit2,#mermaid-svg-E88mGHzEecyAznX1 .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-E88mGHzEecyAznX1 .doneCrit0,#mermaid-svg-E88mGHzEecyAznX1 .doneCrit1,#mermaid-svg-E88mGHzEecyAznX1 .doneCrit2,#mermaid-svg-E88mGHzEecyAznX1 .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-E88mGHzEecyAznX1 .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-E88mGHzEecyAznX1 .milestoneText{font-style:italic}#mermaid-svg-E88mGHzEecyAznX1 .doneCritText0,#mermaid-svg-E88mGHzEecyAznX1 .doneCritText1,#mermaid-svg-E88mGHzEecyAznX1 .doneCritText2,#mermaid-svg-E88mGHzEecyAznX1 .doneCritText3{fill:#000 !important}#mermaid-svg-E88mGHzEecyAznX1 .activeCritText0,#mermaid-svg-E88mGHzEecyAznX1 .activeCritText1,#mermaid-svg-E88mGHzEecyAznX1 .activeCritText2,#mermaid-svg-E88mGHzEecyAznX1 .activeCritText3{fill:#000 !important}#mermaid-svg-E88mGHzEecyAznX1 .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-E88mGHzEecyAznX1 g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-E88mGHzEecyAznX1 g.classGroup text .title{font-weight:bolder}#mermaid-svg-E88mGHzEecyAznX1 g.clickable{cursor:pointer}#mermaid-svg-E88mGHzEecyAznX1 g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-E88mGHzEecyAznX1 g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-E88mGHzEecyAznX1 .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-E88mGHzEecyAznX1 .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-E88mGHzEecyAznX1 .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-E88mGHzEecyAznX1 .dashed-line{stroke-dasharray:3}#mermaid-svg-E88mGHzEecyAznX1 #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-E88mGHzEecyAznX1 #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-E88mGHzEecyAznX1 #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-E88mGHzEecyAznX1 #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-E88mGHzEecyAznX1 #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-E88mGHzEecyAznX1 #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-E88mGHzEecyAznX1 #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-E88mGHzEecyAznX1 #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-E88mGHzEecyAznX1 .commit-id,#mermaid-svg-E88mGHzEecyAznX1 .commit-msg,#mermaid-svg-E88mGHzEecyAznX1 .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-E88mGHzEecyAznX1 .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-E88mGHzEecyAznX1 .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-E88mGHzEecyAznX1 g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-E88mGHzEecyAznX1 g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-E88mGHzEecyAznX1 g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-E88mGHzEecyAznX1 g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-E88mGHzEecyAznX1 g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-E88mGHzEecyAznX1 g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-E88mGHzEecyAznX1 .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-E88mGHzEecyAznX1 .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-E88mGHzEecyAznX1 .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-E88mGHzEecyAznX1 .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-E88mGHzEecyAznX1 .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-E88mGHzEecyAznX1 .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-E88mGHzEecyAznX1 .edgeLabel text{fill:#333}#mermaid-svg-E88mGHzEecyAznX1 .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-E88mGHzEecyAznX1 .node circle.state-start{fill:black;stroke:black}#mermaid-svg-E88mGHzEecyAznX1 .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-E88mGHzEecyAznX1 #statediagram-barbEnd{fill:#9370db}#mermaid-svg-E88mGHzEecyAznX1 .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-E88mGHzEecyAznX1 .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-E88mGHzEecyAznX1 .statediagram-state .divider{stroke:#9370db}#mermaid-svg-E88mGHzEecyAznX1 .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-E88mGHzEecyAznX1 .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-E88mGHzEecyAznX1 .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-E88mGHzEecyAznX1 .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-E88mGHzEecyAznX1 .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-E88mGHzEecyAznX1 .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-E88mGHzEecyAznX1 .note-edge{stroke-dasharray:5}#mermaid-svg-E88mGHzEecyAznX1 .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-E88mGHzEecyAznX1 .error-icon{fill:#522}#mermaid-svg-E88mGHzEecyAznX1 .error-text{fill:#522;stroke:#522}#mermaid-svg-E88mGHzEecyAznX1 .edge-thickness-normal{stroke-width:2px}#mermaid-svg-E88mGHzEecyAznX1 .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-E88mGHzEecyAznX1 .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-E88mGHzEecyAznX1 .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-E88mGHzEecyAznX1 .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-E88mGHzEecyAznX1 .marker{fill:#333}#mermaid-svg-E88mGHzEecyAznX1 .marker.cross{stroke:#333}:root { --mermaid-font-family: "trebuchet ms", verdana, arial;} #mermaid-svg-E88mGHzEecyAznX1 {color: rgba(0, 0, 0, 0.75);font: ;}

点击Button
省略部分中间过程
LinearLayout拦截事件
LinearLayout获得事件
LinearLayout消费事件
事件被消费
Activity消费事件
Button分发事件
Button获得事件
Button消费事件

二、dispatchTouchEvent

在流程概览的图中可以看到,有三个地方使用了dispatchTouchEvent,分别是:ActivityViewGroupView。从系统源码中可以看出,这三个地方的对于这个方法的实现完全不一样,含义也不一样。

1. Activity.dispatchTouchEvent

Activity.dispatchTouchEvent流程图
#mermaid-svg-x3KxbXwoaXpJthDG .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-x3KxbXwoaXpJthDG .label text{fill:#333}#mermaid-svg-x3KxbXwoaXpJthDG .node rect,#mermaid-svg-x3KxbXwoaXpJthDG .node circle,#mermaid-svg-x3KxbXwoaXpJthDG .node ellipse,#mermaid-svg-x3KxbXwoaXpJthDG .node polygon,#mermaid-svg-x3KxbXwoaXpJthDG .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-x3KxbXwoaXpJthDG .node .label{text-align:center;fill:#333}#mermaid-svg-x3KxbXwoaXpJthDG .node.clickable{cursor:pointer}#mermaid-svg-x3KxbXwoaXpJthDG .arrowheadPath{fill:#333}#mermaid-svg-x3KxbXwoaXpJthDG .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-x3KxbXwoaXpJthDG .flowchart-link{stroke:#333;fill:none}#mermaid-svg-x3KxbXwoaXpJthDG .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-x3KxbXwoaXpJthDG .edgeLabel rect{opacity:0.9}#mermaid-svg-x3KxbXwoaXpJthDG .edgeLabel span{color:#333}#mermaid-svg-x3KxbXwoaXpJthDG .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-x3KxbXwoaXpJthDG .cluster text{fill:#333}#mermaid-svg-x3KxbXwoaXpJthDG div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-x3KxbXwoaXpJthDG .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-x3KxbXwoaXpJthDG text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-x3KxbXwoaXpJthDG .actor-line{stroke:grey}#mermaid-svg-x3KxbXwoaXpJthDG .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-x3KxbXwoaXpJthDG .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-x3KxbXwoaXpJthDG #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-x3KxbXwoaXpJthDG .sequenceNumber{fill:#fff}#mermaid-svg-x3KxbXwoaXpJthDG #sequencenumber{fill:#333}#mermaid-svg-x3KxbXwoaXpJthDG #crosshead path{fill:#333;stroke:#333}#mermaid-svg-x3KxbXwoaXpJthDG .messageText{fill:#333;stroke:#333}#mermaid-svg-x3KxbXwoaXpJthDG .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-x3KxbXwoaXpJthDG .labelText,#mermaid-svg-x3KxbXwoaXpJthDG .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-x3KxbXwoaXpJthDG .loopText,#mermaid-svg-x3KxbXwoaXpJthDG .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-x3KxbXwoaXpJthDG .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-x3KxbXwoaXpJthDG .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-x3KxbXwoaXpJthDG .noteText,#mermaid-svg-x3KxbXwoaXpJthDG .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-x3KxbXwoaXpJthDG .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-x3KxbXwoaXpJthDG .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-x3KxbXwoaXpJthDG .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-x3KxbXwoaXpJthDG .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-x3KxbXwoaXpJthDG .section{stroke:none;opacity:0.2}#mermaid-svg-x3KxbXwoaXpJthDG .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-x3KxbXwoaXpJthDG .section2{fill:#fff400}#mermaid-svg-x3KxbXwoaXpJthDG .section1,#mermaid-svg-x3KxbXwoaXpJthDG .section3{fill:#fff;opacity:0.2}#mermaid-svg-x3KxbXwoaXpJthDG .sectionTitle0{fill:#333}#mermaid-svg-x3KxbXwoaXpJthDG .sectionTitle1{fill:#333}#mermaid-svg-x3KxbXwoaXpJthDG .sectionTitle2{fill:#333}#mermaid-svg-x3KxbXwoaXpJthDG .sectionTitle3{fill:#333}#mermaid-svg-x3KxbXwoaXpJthDG .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-x3KxbXwoaXpJthDG .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-x3KxbXwoaXpJthDG .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-x3KxbXwoaXpJthDG .grid path{stroke-width:0}#mermaid-svg-x3KxbXwoaXpJthDG .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-x3KxbXwoaXpJthDG .task{stroke-width:2}#mermaid-svg-x3KxbXwoaXpJthDG .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-x3KxbXwoaXpJthDG .taskText:not([font-size]){font-size:11px}#mermaid-svg-x3KxbXwoaXpJthDG .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-x3KxbXwoaXpJthDG .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-x3KxbXwoaXpJthDG .task.clickable{cursor:pointer}#mermaid-svg-x3KxbXwoaXpJthDG .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-x3KxbXwoaXpJthDG .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-x3KxbXwoaXpJthDG .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-x3KxbXwoaXpJthDG .taskText0,#mermaid-svg-x3KxbXwoaXpJthDG .taskText1,#mermaid-svg-x3KxbXwoaXpJthDG .taskText2,#mermaid-svg-x3KxbXwoaXpJthDG .taskText3{fill:#fff}#mermaid-svg-x3KxbXwoaXpJthDG .task0,#mermaid-svg-x3KxbXwoaXpJthDG .task1,#mermaid-svg-x3KxbXwoaXpJthDG .task2,#mermaid-svg-x3KxbXwoaXpJthDG .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-x3KxbXwoaXpJthDG .taskTextOutside0,#mermaid-svg-x3KxbXwoaXpJthDG .taskTextOutside2{fill:#000}#mermaid-svg-x3KxbXwoaXpJthDG .taskTextOutside1,#mermaid-svg-x3KxbXwoaXpJthDG .taskTextOutside3{fill:#000}#mermaid-svg-x3KxbXwoaXpJthDG .active0,#mermaid-svg-x3KxbXwoaXpJthDG .active1,#mermaid-svg-x3KxbXwoaXpJthDG .active2,#mermaid-svg-x3KxbXwoaXpJthDG .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-x3KxbXwoaXpJthDG .activeText0,#mermaid-svg-x3KxbXwoaXpJthDG .activeText1,#mermaid-svg-x3KxbXwoaXpJthDG .activeText2,#mermaid-svg-x3KxbXwoaXpJthDG .activeText3{fill:#000 !important}#mermaid-svg-x3KxbXwoaXpJthDG .done0,#mermaid-svg-x3KxbXwoaXpJthDG .done1,#mermaid-svg-x3KxbXwoaXpJthDG .done2,#mermaid-svg-x3KxbXwoaXpJthDG .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-x3KxbXwoaXpJthDG .doneText0,#mermaid-svg-x3KxbXwoaXpJthDG .doneText1,#mermaid-svg-x3KxbXwoaXpJthDG .doneText2,#mermaid-svg-x3KxbXwoaXpJthDG .doneText3{fill:#000 !important}#mermaid-svg-x3KxbXwoaXpJthDG .crit0,#mermaid-svg-x3KxbXwoaXpJthDG .crit1,#mermaid-svg-x3KxbXwoaXpJthDG .crit2,#mermaid-svg-x3KxbXwoaXpJthDG .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-x3KxbXwoaXpJthDG .activeCrit0,#mermaid-svg-x3KxbXwoaXpJthDG .activeCrit1,#mermaid-svg-x3KxbXwoaXpJthDG .activeCrit2,#mermaid-svg-x3KxbXwoaXpJthDG .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-x3KxbXwoaXpJthDG .doneCrit0,#mermaid-svg-x3KxbXwoaXpJthDG .doneCrit1,#mermaid-svg-x3KxbXwoaXpJthDG .doneCrit2,#mermaid-svg-x3KxbXwoaXpJthDG .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-x3KxbXwoaXpJthDG .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-x3KxbXwoaXpJthDG .milestoneText{font-style:italic}#mermaid-svg-x3KxbXwoaXpJthDG .doneCritText0,#mermaid-svg-x3KxbXwoaXpJthDG .doneCritText1,#mermaid-svg-x3KxbXwoaXpJthDG .doneCritText2,#mermaid-svg-x3KxbXwoaXpJthDG .doneCritText3{fill:#000 !important}#mermaid-svg-x3KxbXwoaXpJthDG .activeCritText0,#mermaid-svg-x3KxbXwoaXpJthDG .activeCritText1,#mermaid-svg-x3KxbXwoaXpJthDG .activeCritText2,#mermaid-svg-x3KxbXwoaXpJthDG .activeCritText3{fill:#000 !important}#mermaid-svg-x3KxbXwoaXpJthDG .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-x3KxbXwoaXpJthDG g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-x3KxbXwoaXpJthDG g.classGroup text .title{font-weight:bolder}#mermaid-svg-x3KxbXwoaXpJthDG g.clickable{cursor:pointer}#mermaid-svg-x3KxbXwoaXpJthDG g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-x3KxbXwoaXpJthDG g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-x3KxbXwoaXpJthDG .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-x3KxbXwoaXpJthDG .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-x3KxbXwoaXpJthDG .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-x3KxbXwoaXpJthDG .dashed-line{stroke-dasharray:3}#mermaid-svg-x3KxbXwoaXpJthDG #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-x3KxbXwoaXpJthDG #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-x3KxbXwoaXpJthDG #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-x3KxbXwoaXpJthDG #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-x3KxbXwoaXpJthDG #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-x3KxbXwoaXpJthDG #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-x3KxbXwoaXpJthDG #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-x3KxbXwoaXpJthDG #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-x3KxbXwoaXpJthDG .commit-id,#mermaid-svg-x3KxbXwoaXpJthDG .commit-msg,#mermaid-svg-x3KxbXwoaXpJthDG .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-x3KxbXwoaXpJthDG .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-x3KxbXwoaXpJthDG .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-x3KxbXwoaXpJthDG g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-x3KxbXwoaXpJthDG g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-x3KxbXwoaXpJthDG g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-x3KxbXwoaXpJthDG g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-x3KxbXwoaXpJthDG g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-x3KxbXwoaXpJthDG g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-x3KxbXwoaXpJthDG .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-x3KxbXwoaXpJthDG .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-x3KxbXwoaXpJthDG .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-x3KxbXwoaXpJthDG .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-x3KxbXwoaXpJthDG .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-x3KxbXwoaXpJthDG .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-x3KxbXwoaXpJthDG .edgeLabel text{fill:#333}#mermaid-svg-x3KxbXwoaXpJthDG .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-x3KxbXwoaXpJthDG .node circle.state-start{fill:black;stroke:black}#mermaid-svg-x3KxbXwoaXpJthDG .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-x3KxbXwoaXpJthDG #statediagram-barbEnd{fill:#9370db}#mermaid-svg-x3KxbXwoaXpJthDG .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-x3KxbXwoaXpJthDG .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-x3KxbXwoaXpJthDG .statediagram-state .divider{stroke:#9370db}#mermaid-svg-x3KxbXwoaXpJthDG .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-x3KxbXwoaXpJthDG .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-x3KxbXwoaXpJthDG .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-x3KxbXwoaXpJthDG .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-x3KxbXwoaXpJthDG .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-x3KxbXwoaXpJthDG .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-x3KxbXwoaXpJthDG .note-edge{stroke-dasharray:5}#mermaid-svg-x3KxbXwoaXpJthDG .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-x3KxbXwoaXpJthDG .error-icon{fill:#522}#mermaid-svg-x3KxbXwoaXpJthDG .error-text{fill:#522;stroke:#522}#mermaid-svg-x3KxbXwoaXpJthDG .edge-thickness-normal{stroke-width:2px}#mermaid-svg-x3KxbXwoaXpJthDG .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-x3KxbXwoaXpJthDG .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-x3KxbXwoaXpJthDG .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-x3KxbXwoaXpJthDG .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-x3KxbXwoaXpJthDG .marker{fill:#333}#mermaid-svg-x3KxbXwoaXpJthDG .marker.cross{stroke:#333}:root { --mermaid-font-family: "trebuchet ms", verdana, arial;} #mermaid-svg-x3KxbXwoaXpJthDG {color: rgba(0, 0, 0, 0.75);font: ;}

开始
dispatchTouchEvent
当前是ACTION_DOWN
onUserInteraction
return onTouchEvent
Window.superDispatchTouchEvent
return true
Activity.dispatchTouchEvent中涉及到的部分变量的类图
#mermaid-svg-tw5ILxFpJdK7ZxVB .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-tw5ILxFpJdK7ZxVB .label text{fill:#333}#mermaid-svg-tw5ILxFpJdK7ZxVB .node rect,#mermaid-svg-tw5ILxFpJdK7ZxVB .node circle,#mermaid-svg-tw5ILxFpJdK7ZxVB .node ellipse,#mermaid-svg-tw5ILxFpJdK7ZxVB .node polygon,#mermaid-svg-tw5ILxFpJdK7ZxVB .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-tw5ILxFpJdK7ZxVB .node .label{text-align:center;fill:#333}#mermaid-svg-tw5ILxFpJdK7ZxVB .node.clickable{cursor:pointer}#mermaid-svg-tw5ILxFpJdK7ZxVB .arrowheadPath{fill:#333}#mermaid-svg-tw5ILxFpJdK7ZxVB .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-tw5ILxFpJdK7ZxVB .flowchart-link{stroke:#333;fill:none}#mermaid-svg-tw5ILxFpJdK7ZxVB .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-tw5ILxFpJdK7ZxVB .edgeLabel rect{opacity:0.9}#mermaid-svg-tw5ILxFpJdK7ZxVB .edgeLabel span{color:#333}#mermaid-svg-tw5ILxFpJdK7ZxVB .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-tw5ILxFpJdK7ZxVB .cluster text{fill:#333}#mermaid-svg-tw5ILxFpJdK7ZxVB div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-tw5ILxFpJdK7ZxVB .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-tw5ILxFpJdK7ZxVB text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-tw5ILxFpJdK7ZxVB .actor-line{stroke:grey}#mermaid-svg-tw5ILxFpJdK7ZxVB .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-tw5ILxFpJdK7ZxVB .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-tw5ILxFpJdK7ZxVB #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-tw5ILxFpJdK7ZxVB .sequenceNumber{fill:#fff}#mermaid-svg-tw5ILxFpJdK7ZxVB #sequencenumber{fill:#333}#mermaid-svg-tw5ILxFpJdK7ZxVB #crosshead path{fill:#333;stroke:#333}#mermaid-svg-tw5ILxFpJdK7ZxVB .messageText{fill:#333;stroke:#333}#mermaid-svg-tw5ILxFpJdK7ZxVB .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-tw5ILxFpJdK7ZxVB .labelText,#mermaid-svg-tw5ILxFpJdK7ZxVB .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-tw5ILxFpJdK7ZxVB .loopText,#mermaid-svg-tw5ILxFpJdK7ZxVB .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-tw5ILxFpJdK7ZxVB .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-tw5ILxFpJdK7ZxVB .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-tw5ILxFpJdK7ZxVB .noteText,#mermaid-svg-tw5ILxFpJdK7ZxVB .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-tw5ILxFpJdK7ZxVB .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-tw5ILxFpJdK7ZxVB .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-tw5ILxFpJdK7ZxVB .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-tw5ILxFpJdK7ZxVB .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-tw5ILxFpJdK7ZxVB .section{stroke:none;opacity:0.2}#mermaid-svg-tw5ILxFpJdK7ZxVB .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-tw5ILxFpJdK7ZxVB .section2{fill:#fff400}#mermaid-svg-tw5ILxFpJdK7ZxVB .section1,#mermaid-svg-tw5ILxFpJdK7ZxVB .section3{fill:#fff;opacity:0.2}#mermaid-svg-tw5ILxFpJdK7ZxVB .sectionTitle0{fill:#333}#mermaid-svg-tw5ILxFpJdK7ZxVB .sectionTitle1{fill:#333}#mermaid-svg-tw5ILxFpJdK7ZxVB .sectionTitle2{fill:#333}#mermaid-svg-tw5ILxFpJdK7ZxVB .sectionTitle3{fill:#333}#mermaid-svg-tw5ILxFpJdK7ZxVB .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-tw5ILxFpJdK7ZxVB .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-tw5ILxFpJdK7ZxVB .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-tw5ILxFpJdK7ZxVB .grid path{stroke-width:0}#mermaid-svg-tw5ILxFpJdK7ZxVB .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-tw5ILxFpJdK7ZxVB .task{stroke-width:2}#mermaid-svg-tw5ILxFpJdK7ZxVB .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-tw5ILxFpJdK7ZxVB .taskText:not([font-size]){font-size:11px}#mermaid-svg-tw5ILxFpJdK7ZxVB .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-tw5ILxFpJdK7ZxVB .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-tw5ILxFpJdK7ZxVB .task.clickable{cursor:pointer}#mermaid-svg-tw5ILxFpJdK7ZxVB .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-tw5ILxFpJdK7ZxVB .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-tw5ILxFpJdK7ZxVB .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-tw5ILxFpJdK7ZxVB .taskText0,#mermaid-svg-tw5ILxFpJdK7ZxVB .taskText1,#mermaid-svg-tw5ILxFpJdK7ZxVB .taskText2,#mermaid-svg-tw5ILxFpJdK7ZxVB .taskText3{fill:#fff}#mermaid-svg-tw5ILxFpJdK7ZxVB .task0,#mermaid-svg-tw5ILxFpJdK7ZxVB .task1,#mermaid-svg-tw5ILxFpJdK7ZxVB .task2,#mermaid-svg-tw5ILxFpJdK7ZxVB .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-tw5ILxFpJdK7ZxVB .taskTextOutside0,#mermaid-svg-tw5ILxFpJdK7ZxVB .taskTextOutside2{fill:#000}#mermaid-svg-tw5ILxFpJdK7ZxVB .taskTextOutside1,#mermaid-svg-tw5ILxFpJdK7ZxVB .taskTextOutside3{fill:#000}#mermaid-svg-tw5ILxFpJdK7ZxVB .active0,#mermaid-svg-tw5ILxFpJdK7ZxVB .active1,#mermaid-svg-tw5ILxFpJdK7ZxVB .active2,#mermaid-svg-tw5ILxFpJdK7ZxVB .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-tw5ILxFpJdK7ZxVB .activeText0,#mermaid-svg-tw5ILxFpJdK7ZxVB .activeText1,#mermaid-svg-tw5ILxFpJdK7ZxVB .activeText2,#mermaid-svg-tw5ILxFpJdK7ZxVB .activeText3{fill:#000 !important}#mermaid-svg-tw5ILxFpJdK7ZxVB .done0,#mermaid-svg-tw5ILxFpJdK7ZxVB .done1,#mermaid-svg-tw5ILxFpJdK7ZxVB .done2,#mermaid-svg-tw5ILxFpJdK7ZxVB .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-tw5ILxFpJdK7ZxVB .doneText0,#mermaid-svg-tw5ILxFpJdK7ZxVB .doneText1,#mermaid-svg-tw5ILxFpJdK7ZxVB .doneText2,#mermaid-svg-tw5ILxFpJdK7ZxVB .doneText3{fill:#000 !important}#mermaid-svg-tw5ILxFpJdK7ZxVB .crit0,#mermaid-svg-tw5ILxFpJdK7ZxVB .crit1,#mermaid-svg-tw5ILxFpJdK7ZxVB .crit2,#mermaid-svg-tw5ILxFpJdK7ZxVB .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-tw5ILxFpJdK7ZxVB .activeCrit0,#mermaid-svg-tw5ILxFpJdK7ZxVB .activeCrit1,#mermaid-svg-tw5ILxFpJdK7ZxVB .activeCrit2,#mermaid-svg-tw5ILxFpJdK7ZxVB .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-tw5ILxFpJdK7ZxVB .doneCrit0,#mermaid-svg-tw5ILxFpJdK7ZxVB .doneCrit1,#mermaid-svg-tw5ILxFpJdK7ZxVB .doneCrit2,#mermaid-svg-tw5ILxFpJdK7ZxVB .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-tw5ILxFpJdK7ZxVB .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-tw5ILxFpJdK7ZxVB .milestoneText{font-style:italic}#mermaid-svg-tw5ILxFpJdK7ZxVB .doneCritText0,#mermaid-svg-tw5ILxFpJdK7ZxVB .doneCritText1,#mermaid-svg-tw5ILxFpJdK7ZxVB .doneCritText2,#mermaid-svg-tw5ILxFpJdK7ZxVB .doneCritText3{fill:#000 !important}#mermaid-svg-tw5ILxFpJdK7ZxVB .activeCritText0,#mermaid-svg-tw5ILxFpJdK7ZxVB .activeCritText1,#mermaid-svg-tw5ILxFpJdK7ZxVB .activeCritText2,#mermaid-svg-tw5ILxFpJdK7ZxVB .activeCritText3{fill:#000 !important}#mermaid-svg-tw5ILxFpJdK7ZxVB .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-tw5ILxFpJdK7ZxVB g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-tw5ILxFpJdK7ZxVB g.classGroup text .title{font-weight:bolder}#mermaid-svg-tw5ILxFpJdK7ZxVB g.clickable{cursor:pointer}#mermaid-svg-tw5ILxFpJdK7ZxVB g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-tw5ILxFpJdK7ZxVB g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-tw5ILxFpJdK7ZxVB .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-tw5ILxFpJdK7ZxVB .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-tw5ILxFpJdK7ZxVB .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-tw5ILxFpJdK7ZxVB .dashed-line{stroke-dasharray:3}#mermaid-svg-tw5ILxFpJdK7ZxVB #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-tw5ILxFpJdK7ZxVB #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-tw5ILxFpJdK7ZxVB #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-tw5ILxFpJdK7ZxVB #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-tw5ILxFpJdK7ZxVB #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-tw5ILxFpJdK7ZxVB #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-tw5ILxFpJdK7ZxVB #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-tw5ILxFpJdK7ZxVB #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-tw5ILxFpJdK7ZxVB .commit-id,#mermaid-svg-tw5ILxFpJdK7ZxVB .commit-msg,#mermaid-svg-tw5ILxFpJdK7ZxVB .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-tw5ILxFpJdK7ZxVB .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-tw5ILxFpJdK7ZxVB .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-tw5ILxFpJdK7ZxVB g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-tw5ILxFpJdK7ZxVB g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-tw5ILxFpJdK7ZxVB g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-tw5ILxFpJdK7ZxVB g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-tw5ILxFpJdK7ZxVB g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-tw5ILxFpJdK7ZxVB g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-tw5ILxFpJdK7ZxVB .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-tw5ILxFpJdK7ZxVB .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-tw5ILxFpJdK7ZxVB .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-tw5ILxFpJdK7ZxVB .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-tw5ILxFpJdK7ZxVB .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-tw5ILxFpJdK7ZxVB .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-tw5ILxFpJdK7ZxVB .edgeLabel text{fill:#333}#mermaid-svg-tw5ILxFpJdK7ZxVB .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-tw5ILxFpJdK7ZxVB .node circle.state-start{fill:black;stroke:black}#mermaid-svg-tw5ILxFpJdK7ZxVB .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-tw5ILxFpJdK7ZxVB #statediagram-barbEnd{fill:#9370db}#mermaid-svg-tw5ILxFpJdK7ZxVB .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-tw5ILxFpJdK7ZxVB .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-tw5ILxFpJdK7ZxVB .statediagram-state .divider{stroke:#9370db}#mermaid-svg-tw5ILxFpJdK7ZxVB .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-tw5ILxFpJdK7ZxVB .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-tw5ILxFpJdK7ZxVB .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-tw5ILxFpJdK7ZxVB .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-tw5ILxFpJdK7ZxVB .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-tw5ILxFpJdK7ZxVB .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-tw5ILxFpJdK7ZxVB .note-edge{stroke-dasharray:5}#mermaid-svg-tw5ILxFpJdK7ZxVB .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-tw5ILxFpJdK7ZxVB .error-icon{fill:#522}#mermaid-svg-tw5ILxFpJdK7ZxVB .error-text{fill:#522;stroke:#522}#mermaid-svg-tw5ILxFpJdK7ZxVB .edge-thickness-normal{stroke-width:2px}#mermaid-svg-tw5ILxFpJdK7ZxVB .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-tw5ILxFpJdK7ZxVB .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-tw5ILxFpJdK7ZxVB .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-tw5ILxFpJdK7ZxVB .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-tw5ILxFpJdK7ZxVB .marker{fill:#333}#mermaid-svg-tw5ILxFpJdK7ZxVB .marker.cross{stroke:#333}:root { --mermaid-font-family: "trebuchet ms", verdana, arial;} #mermaid-svg-tw5ILxFpJdK7ZxVB {color: rgba(0, 0, 0, 0.75);font: ;} Activity +dispatchTouchEvent(MotionEvent ev) : boolean +onUserInteraction() +onUserLeaveHint() Window PhoneWindow FrameLayout DecorView

Activity.java

public boolean dispatchTouchEvent(MotionEvent ev) {if (ev.getAction() == MotionEvent.ACTION_DOWN) {onUserInteraction();}if (getWindow().superDispatchTouchEvent(ev)) {return true;}return onTouchEvent(ev);
}public Window getWindow() {return mWindow;
}

(1)onUserInteraction和onUserLeaveHint

onUserInteractiononUserLeaveHint是成对使用的回调方法,需要用户自己实现。可以用于处理或取消状态栏的通知列表。

onUserInteractionkey、touch、trackball event分发给Activity的时候调用。

onUserLeaveHintActivity回到后台之前,执行onPause之前调用。

(2)PhoneWindow

PhoneWindow.java

public class PhoneWindow extends Window implements MenuBuilder.Callback {private DecorView mDecor;public boolean superDispatchTouchEvent(MotionEvent event) {return mDecor.superDispatchTouchEvent(event);}private final class DecorView extends FrameLayout implements RootViewSurfaceTaker {public boolean superDispatchTouchEvent(MotionEvent event) {return super.dispatchTouchEvent(event);}}
}

Window是个abstract class,它唯一的实现类是android.policy.PhoneWindow

PhoneWindow是一个顶级窗口,它持有的mDecor作为该Windowview,是顶级View

DecorView继承于FrameLayout,也就是说它是个ViewGroupFrameLayout中没有重写dispatchTouchEvent,所以DecorView执行super.dispatchTouchEvent时,就是在执行ViewGroup.dispatchTouchEvent

PhoneWindow执行superDispatchTouchEvent实现了从Activity.dispatchTouchEvent过渡到ViewGroup.dispatchTouchEvent。也就是说把事件从Activity传递到ViewGroup。从代码上看,该过程是必然会发生的,没有被拦截的情况出现。

(3)返回值

可以见到Activity.dispatchTouchEvent是有返回值的,但是这里不管返回TRUE还是FALSE,都代表了消费了事件。当返回FALSE时,必然是执行了onTouchEvent。当返回TRUE时,一定分发了事件,但可能执行了onTouchEvent

2. ViewGroup.dispatchTouchEvent

  • ViewGroup事件分发流程图:
#mermaid-svg-o9XeineCOeFk5UMk .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-o9XeineCOeFk5UMk .label text{fill:#333}#mermaid-svg-o9XeineCOeFk5UMk .node rect,#mermaid-svg-o9XeineCOeFk5UMk .node circle,#mermaid-svg-o9XeineCOeFk5UMk .node ellipse,#mermaid-svg-o9XeineCOeFk5UMk .node polygon,#mermaid-svg-o9XeineCOeFk5UMk .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-o9XeineCOeFk5UMk .node .label{text-align:center;fill:#333}#mermaid-svg-o9XeineCOeFk5UMk .node.clickable{cursor:pointer}#mermaid-svg-o9XeineCOeFk5UMk .arrowheadPath{fill:#333}#mermaid-svg-o9XeineCOeFk5UMk .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-o9XeineCOeFk5UMk .flowchart-link{stroke:#333;fill:none}#mermaid-svg-o9XeineCOeFk5UMk .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-o9XeineCOeFk5UMk .edgeLabel rect{opacity:0.9}#mermaid-svg-o9XeineCOeFk5UMk .edgeLabel span{color:#333}#mermaid-svg-o9XeineCOeFk5UMk .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-o9XeineCOeFk5UMk .cluster text{fill:#333}#mermaid-svg-o9XeineCOeFk5UMk div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-o9XeineCOeFk5UMk .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-o9XeineCOeFk5UMk text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-o9XeineCOeFk5UMk .actor-line{stroke:grey}#mermaid-svg-o9XeineCOeFk5UMk .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-o9XeineCOeFk5UMk .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-o9XeineCOeFk5UMk #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-o9XeineCOeFk5UMk .sequenceNumber{fill:#fff}#mermaid-svg-o9XeineCOeFk5UMk #sequencenumber{fill:#333}#mermaid-svg-o9XeineCOeFk5UMk #crosshead path{fill:#333;stroke:#333}#mermaid-svg-o9XeineCOeFk5UMk .messageText{fill:#333;stroke:#333}#mermaid-svg-o9XeineCOeFk5UMk .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-o9XeineCOeFk5UMk .labelText,#mermaid-svg-o9XeineCOeFk5UMk .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-o9XeineCOeFk5UMk .loopText,#mermaid-svg-o9XeineCOeFk5UMk .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-o9XeineCOeFk5UMk .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-o9XeineCOeFk5UMk .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-o9XeineCOeFk5UMk .noteText,#mermaid-svg-o9XeineCOeFk5UMk .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-o9XeineCOeFk5UMk .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-o9XeineCOeFk5UMk .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-o9XeineCOeFk5UMk .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-o9XeineCOeFk5UMk .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-o9XeineCOeFk5UMk .section{stroke:none;opacity:0.2}#mermaid-svg-o9XeineCOeFk5UMk .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-o9XeineCOeFk5UMk .section2{fill:#fff400}#mermaid-svg-o9XeineCOeFk5UMk .section1,#mermaid-svg-o9XeineCOeFk5UMk .section3{fill:#fff;opacity:0.2}#mermaid-svg-o9XeineCOeFk5UMk .sectionTitle0{fill:#333}#mermaid-svg-o9XeineCOeFk5UMk .sectionTitle1{fill:#333}#mermaid-svg-o9XeineCOeFk5UMk .sectionTitle2{fill:#333}#mermaid-svg-o9XeineCOeFk5UMk .sectionTitle3{fill:#333}#mermaid-svg-o9XeineCOeFk5UMk .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-o9XeineCOeFk5UMk .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-o9XeineCOeFk5UMk .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-o9XeineCOeFk5UMk .grid path{stroke-width:0}#mermaid-svg-o9XeineCOeFk5UMk .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-o9XeineCOeFk5UMk .task{stroke-width:2}#mermaid-svg-o9XeineCOeFk5UMk .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-o9XeineCOeFk5UMk .taskText:not([font-size]){font-size:11px}#mermaid-svg-o9XeineCOeFk5UMk .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-o9XeineCOeFk5UMk .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-o9XeineCOeFk5UMk .task.clickable{cursor:pointer}#mermaid-svg-o9XeineCOeFk5UMk .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-o9XeineCOeFk5UMk .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-o9XeineCOeFk5UMk .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-o9XeineCOeFk5UMk .taskText0,#mermaid-svg-o9XeineCOeFk5UMk .taskText1,#mermaid-svg-o9XeineCOeFk5UMk .taskText2,#mermaid-svg-o9XeineCOeFk5UMk .taskText3{fill:#fff}#mermaid-svg-o9XeineCOeFk5UMk .task0,#mermaid-svg-o9XeineCOeFk5UMk .task1,#mermaid-svg-o9XeineCOeFk5UMk .task2,#mermaid-svg-o9XeineCOeFk5UMk .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-o9XeineCOeFk5UMk .taskTextOutside0,#mermaid-svg-o9XeineCOeFk5UMk .taskTextOutside2{fill:#000}#mermaid-svg-o9XeineCOeFk5UMk .taskTextOutside1,#mermaid-svg-o9XeineCOeFk5UMk .taskTextOutside3{fill:#000}#mermaid-svg-o9XeineCOeFk5UMk .active0,#mermaid-svg-o9XeineCOeFk5UMk .active1,#mermaid-svg-o9XeineCOeFk5UMk .active2,#mermaid-svg-o9XeineCOeFk5UMk .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-o9XeineCOeFk5UMk .activeText0,#mermaid-svg-o9XeineCOeFk5UMk .activeText1,#mermaid-svg-o9XeineCOeFk5UMk .activeText2,#mermaid-svg-o9XeineCOeFk5UMk .activeText3{fill:#000 !important}#mermaid-svg-o9XeineCOeFk5UMk .done0,#mermaid-svg-o9XeineCOeFk5UMk .done1,#mermaid-svg-o9XeineCOeFk5UMk .done2,#mermaid-svg-o9XeineCOeFk5UMk .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-o9XeineCOeFk5UMk .doneText0,#mermaid-svg-o9XeineCOeFk5UMk .doneText1,#mermaid-svg-o9XeineCOeFk5UMk .doneText2,#mermaid-svg-o9XeineCOeFk5UMk .doneText3{fill:#000 !important}#mermaid-svg-o9XeineCOeFk5UMk .crit0,#mermaid-svg-o9XeineCOeFk5UMk .crit1,#mermaid-svg-o9XeineCOeFk5UMk .crit2,#mermaid-svg-o9XeineCOeFk5UMk .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-o9XeineCOeFk5UMk .activeCrit0,#mermaid-svg-o9XeineCOeFk5UMk .activeCrit1,#mermaid-svg-o9XeineCOeFk5UMk .activeCrit2,#mermaid-svg-o9XeineCOeFk5UMk .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-o9XeineCOeFk5UMk .doneCrit0,#mermaid-svg-o9XeineCOeFk5UMk .doneCrit1,#mermaid-svg-o9XeineCOeFk5UMk .doneCrit2,#mermaid-svg-o9XeineCOeFk5UMk .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-o9XeineCOeFk5UMk .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-o9XeineCOeFk5UMk .milestoneText{font-style:italic}#mermaid-svg-o9XeineCOeFk5UMk .doneCritText0,#mermaid-svg-o9XeineCOeFk5UMk .doneCritText1,#mermaid-svg-o9XeineCOeFk5UMk .doneCritText2,#mermaid-svg-o9XeineCOeFk5UMk .doneCritText3{fill:#000 !important}#mermaid-svg-o9XeineCOeFk5UMk .activeCritText0,#mermaid-svg-o9XeineCOeFk5UMk .activeCritText1,#mermaid-svg-o9XeineCOeFk5UMk .activeCritText2,#mermaid-svg-o9XeineCOeFk5UMk .activeCritText3{fill:#000 !important}#mermaid-svg-o9XeineCOeFk5UMk .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-o9XeineCOeFk5UMk g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-o9XeineCOeFk5UMk g.classGroup text .title{font-weight:bolder}#mermaid-svg-o9XeineCOeFk5UMk g.clickable{cursor:pointer}#mermaid-svg-o9XeineCOeFk5UMk g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-o9XeineCOeFk5UMk g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-o9XeineCOeFk5UMk .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-o9XeineCOeFk5UMk .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-o9XeineCOeFk5UMk .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-o9XeineCOeFk5UMk .dashed-line{stroke-dasharray:3}#mermaid-svg-o9XeineCOeFk5UMk #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-o9XeineCOeFk5UMk #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-o9XeineCOeFk5UMk #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-o9XeineCOeFk5UMk #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-o9XeineCOeFk5UMk #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-o9XeineCOeFk5UMk #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-o9XeineCOeFk5UMk #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-o9XeineCOeFk5UMk #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-o9XeineCOeFk5UMk .commit-id,#mermaid-svg-o9XeineCOeFk5UMk .commit-msg,#mermaid-svg-o9XeineCOeFk5UMk .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-o9XeineCOeFk5UMk .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-o9XeineCOeFk5UMk .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-o9XeineCOeFk5UMk g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-o9XeineCOeFk5UMk g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-o9XeineCOeFk5UMk g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-o9XeineCOeFk5UMk g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-o9XeineCOeFk5UMk g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-o9XeineCOeFk5UMk g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-o9XeineCOeFk5UMk .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-o9XeineCOeFk5UMk .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-o9XeineCOeFk5UMk .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-o9XeineCOeFk5UMk .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-o9XeineCOeFk5UMk .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-o9XeineCOeFk5UMk .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-o9XeineCOeFk5UMk .edgeLabel text{fill:#333}#mermaid-svg-o9XeineCOeFk5UMk .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-o9XeineCOeFk5UMk .node circle.state-start{fill:black;stroke:black}#mermaid-svg-o9XeineCOeFk5UMk .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-o9XeineCOeFk5UMk #statediagram-barbEnd{fill:#9370db}#mermaid-svg-o9XeineCOeFk5UMk .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-o9XeineCOeFk5UMk .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-o9XeineCOeFk5UMk .statediagram-state .divider{stroke:#9370db}#mermaid-svg-o9XeineCOeFk5UMk .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-o9XeineCOeFk5UMk .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-o9XeineCOeFk5UMk .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-o9XeineCOeFk5UMk .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-o9XeineCOeFk5UMk .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-o9XeineCOeFk5UMk .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-o9XeineCOeFk5UMk .note-edge{stroke-dasharray:5}#mermaid-svg-o9XeineCOeFk5UMk .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-o9XeineCOeFk5UMk .error-icon{fill:#522}#mermaid-svg-o9XeineCOeFk5UMk .error-text{fill:#522;stroke:#522}#mermaid-svg-o9XeineCOeFk5UMk .edge-thickness-normal{stroke-width:2px}#mermaid-svg-o9XeineCOeFk5UMk .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-o9XeineCOeFk5UMk .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-o9XeineCOeFk5UMk .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-o9XeineCOeFk5UMk .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-o9XeineCOeFk5UMk .marker{fill:#333}#mermaid-svg-o9XeineCOeFk5UMk .marker.cross{stroke:#333}:root { --mermaid-font-family: "trebuchet ms", verdana, arial;} #mermaid-svg-o9XeineCOeFk5UMk {color: rgba(0, 0, 0, 0.75);font: ;}

开始
dispatchTouchEvent
事件被INTERCEPTED
onInterceptTouchEvent
onTouchEvent
结束
child.dispatchTouchEvent
child.onTouchEvent

ViewGroup.java

public boolean dispatchTouchEvent(MotionEvent ev) {// Check for interception.final boolean intercepted;if (actionMasked == MotionEvent.ACTION_DOWN|| mFirstTouchTarget != null) {final boolean disallowIntercept = (mGroupFlags & FLAG_DISALLOW_INTERCEPT) != 0;if (!disallowIntercept) {intercepted = onInterceptTouchEvent(ev);ev.setAction(action); // restore action in case it was changed} else {intercepted = false;}} else {// There are no touch targets and this action is not an initial down// so this view group continues to intercept touches.intercepted = true;}// Check for cancelation.final boolean canceled = resetCancelNextUpFlag(this)|| actionMasked == MotionEvent.ACTION_CANCEL;if (!canceled && !intercepted) {final View[] children = mChildren;for (int i = childrenCount - 1; i >= 0; i--) {final int childIndex = customOrder? getChildDrawingOrder(childrenCount, i) : i;final View child = (preorderedList == null)? children[childIndex] : preorderedList.get(childIndex);if (dispatchTransformedTouchEvent(ev, false, child, idBitsToAssign)) {}}}
}private boolean dispatchTransformedTouchEvent(MotionEvent event, boolean cancel, View child, int desiredPointerIdBits) {// Perform any necessary transformations and dispatch.if (child == null) {handled = super.dispatchTouchEvent(transformedEvent);} else {handled = child.dispatchTouchEvent(transformedEvent);}
}

ViewGroup在事件分发的时候跟Activity最大的不同是,要先判断是否该事件是否被CANCELEDINTERCEPTED,然后才决定是否要继续往下dispatch

如果要继续往下分发,那么必须找到触摸的那个子view,实现的方式就是最普通、最直接的遍历整个子View数组。如果找到的子view的边界符合触摸事件的坐标条件且可以接收事件,那么就可以分发了。

在继续往下分发的过程中,如果符合条件的子view是空的,那么事件会调用super.dispatchTouchEevnt处理。否则,分发给子view

onInterceptTouchEvent

ViewGroup.java

// First touch target in the linked list of touch targets.
private TouchTarget mFirstTouchTarget;/*** Implement this method to intercept all touch screen motion events.  This* allows you to watch events as they are dispatched to your children, and* take ownership of the current gesture at any point.** <p>Using this function takes some care, as it has a fairly complicated* interaction with {@link View#onTouchEvent(MotionEvent)* View.onTouchEvent(MotionEvent)}, and using it requires implementing* that method as well as this one in the correct way.  Events will be* received in the following order:** <ol>* <li> You will receive the down event here.* <li> The down event will be handled either by a child of this view* group, or given to your own onTouchEvent() method to handle; this means* you should implement onTouchEvent() to return true, so you will* continue to see the rest of the gesture (instead of looking for* a parent view to handle it).  Also, by returning true from* onTouchEvent(), you will not receive any following* events in onInterceptTouchEvent() and all touch processing must* happen in onTouchEvent() like normal.* <li> For as long as you return false from this function, each following* event (up to and including the final up) will be delivered first here* and then to the target's onTouchEvent().* <li> If you return true from here, you will not receive any* following events: the target view will receive the same event but* with the action {@link MotionEvent#ACTION_CANCEL}, and all further* events will be delivered to your onTouchEvent() method and no longer* appear here.* </ol>** @param ev The motion event being dispatched down the hierarchy.* @return Return true to steal motion events from the children and have* them dispatched to this ViewGroup through onTouchEvent().* The current target will receive an ACTION_CANCEL event, and no further* messages will be delivered here.*/
public boolean onInterceptTouchEvent(MotionEvent ev) {return false;
}public boolean dispatchTouchEvent(MotionEvent ev) {// Handle an initial down.if (actionMasked == MotionEvent.ACTION_DOWN) {resetTouchState();}// Dispatch to touch targets.if (mFirstTouchTarget == null) {// No touch targets so treat this as an ordinary view.handled = dispatchTransformedTouchEvent(ev, canceled, null, TouchTarget.ALL_POINTER_IDS);} else {// Dispatch to touch targets, excluding the new touch target if we already// dispatched to it.  Cancel touch targets if necessary.TouchTarget predecessor = null;TouchTarget target = mFirstTouchTarget;while (target != null) {final TouchTarget next = target.next;if (alreadyDispatchedToNewTouchTarget && target == newTouchTarget) {handled = true;} else {final boolean cancelChild = resetCancelNextUpFlag(target.child) || intercepted;if (dispatchTransformedTouchEvent(ev, cancelChild, target.child, target.pointerIdBits)) {handled = true;}if (cancelChild) {if (predecessor == null) {mFirstTouchTarget = next;} else {predecessor.next = next;}target.recycle();target = next;continue;}}predecessor = target;target = next;}}
}/*** Resets all touch state in preparation for a new cycle.*/
private void resetTouchState() {clearTouchTargets();
}/*** Clears all touch targets.*/
private void clearTouchTargets() {TouchTarget target = mFirstTouchTarget;if (target != null) {mFirstTouchTarget = null;}
}private boolean dispatchTransformedTouchEvent(MotionEvent event, boolean cancel, View child, int desiredPointerIdBits) {final boolean handled;// Canceling motions is a special case.  We don't need to perform any transformations// or filtering.  The important part is the action, not the contents.final int oldAction = event.getAction();if (cancel || oldAction == MotionEvent.ACTION_CANCEL) {event.setAction(MotionEvent.ACTION_CANCEL);if (child == null) {handled = super.dispatchTouchEvent(event);} else {handled = child.dispatchTouchEvent(event);}event.setAction(oldAction);return handled;}
}

只有ViewGrouponInterceptTouchEvent这个方法,且返回值默认是FALSE。源码中全靠注释,代码只有一句return false;

ViewGroup.dispatchTouchEvent中可以看出,事件处理的周期从ACTION_DOWN开始,于下一个ACTION_DOWN的前一个事件结束。onInterceptTouchEvent的返回值表示是否要拦截这个事件。以一个周期为例,如果ViewGroup.onInterceptTouchEvent返回TRUE,那么这个触摸事件就会直接派发给ViewGroup自己。ACTION_DOWN事件只派发给ViewGroup,其他子view收不到任何事件。在这个周期结束之前,ViewGroup会持续拦截所有事件,但是只有事件为ACTION_DOWN时,其他子view才收不到;如果事件为ACTION_MOVE等事件,其他子view会收到事件ACTION_CANCEL

onInterceptTouchEvent返回TRUE时,ViewGroup会调用super.dispatchTouchEvent,也就是会调用View.dispatchTouchEvent

3. View.dispatchTouchEvent

  • View.dispatchTouchEvent流程图:
#mermaid-svg-gXFUFE7Y05ebv6QU .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-gXFUFE7Y05ebv6QU .label text{fill:#333}#mermaid-svg-gXFUFE7Y05ebv6QU .node rect,#mermaid-svg-gXFUFE7Y05ebv6QU .node circle,#mermaid-svg-gXFUFE7Y05ebv6QU .node ellipse,#mermaid-svg-gXFUFE7Y05ebv6QU .node polygon,#mermaid-svg-gXFUFE7Y05ebv6QU .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-gXFUFE7Y05ebv6QU .node .label{text-align:center;fill:#333}#mermaid-svg-gXFUFE7Y05ebv6QU .node.clickable{cursor:pointer}#mermaid-svg-gXFUFE7Y05ebv6QU .arrowheadPath{fill:#333}#mermaid-svg-gXFUFE7Y05ebv6QU .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-gXFUFE7Y05ebv6QU .flowchart-link{stroke:#333;fill:none}#mermaid-svg-gXFUFE7Y05ebv6QU .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-gXFUFE7Y05ebv6QU .edgeLabel rect{opacity:0.9}#mermaid-svg-gXFUFE7Y05ebv6QU .edgeLabel span{color:#333}#mermaid-svg-gXFUFE7Y05ebv6QU .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-gXFUFE7Y05ebv6QU .cluster text{fill:#333}#mermaid-svg-gXFUFE7Y05ebv6QU div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-gXFUFE7Y05ebv6QU .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-gXFUFE7Y05ebv6QU text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-gXFUFE7Y05ebv6QU .actor-line{stroke:grey}#mermaid-svg-gXFUFE7Y05ebv6QU .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-gXFUFE7Y05ebv6QU .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-gXFUFE7Y05ebv6QU #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-gXFUFE7Y05ebv6QU .sequenceNumber{fill:#fff}#mermaid-svg-gXFUFE7Y05ebv6QU #sequencenumber{fill:#333}#mermaid-svg-gXFUFE7Y05ebv6QU #crosshead path{fill:#333;stroke:#333}#mermaid-svg-gXFUFE7Y05ebv6QU .messageText{fill:#333;stroke:#333}#mermaid-svg-gXFUFE7Y05ebv6QU .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-gXFUFE7Y05ebv6QU .labelText,#mermaid-svg-gXFUFE7Y05ebv6QU .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-gXFUFE7Y05ebv6QU .loopText,#mermaid-svg-gXFUFE7Y05ebv6QU .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-gXFUFE7Y05ebv6QU .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-gXFUFE7Y05ebv6QU .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-gXFUFE7Y05ebv6QU .noteText,#mermaid-svg-gXFUFE7Y05ebv6QU .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-gXFUFE7Y05ebv6QU .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-gXFUFE7Y05ebv6QU .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-gXFUFE7Y05ebv6QU .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-gXFUFE7Y05ebv6QU .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-gXFUFE7Y05ebv6QU .section{stroke:none;opacity:0.2}#mermaid-svg-gXFUFE7Y05ebv6QU .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-gXFUFE7Y05ebv6QU .section2{fill:#fff400}#mermaid-svg-gXFUFE7Y05ebv6QU .section1,#mermaid-svg-gXFUFE7Y05ebv6QU .section3{fill:#fff;opacity:0.2}#mermaid-svg-gXFUFE7Y05ebv6QU .sectionTitle0{fill:#333}#mermaid-svg-gXFUFE7Y05ebv6QU .sectionTitle1{fill:#333}#mermaid-svg-gXFUFE7Y05ebv6QU .sectionTitle2{fill:#333}#mermaid-svg-gXFUFE7Y05ebv6QU .sectionTitle3{fill:#333}#mermaid-svg-gXFUFE7Y05ebv6QU .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-gXFUFE7Y05ebv6QU .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-gXFUFE7Y05ebv6QU .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-gXFUFE7Y05ebv6QU .grid path{stroke-width:0}#mermaid-svg-gXFUFE7Y05ebv6QU .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-gXFUFE7Y05ebv6QU .task{stroke-width:2}#mermaid-svg-gXFUFE7Y05ebv6QU .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-gXFUFE7Y05ebv6QU .taskText:not([font-size]){font-size:11px}#mermaid-svg-gXFUFE7Y05ebv6QU .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-gXFUFE7Y05ebv6QU .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-gXFUFE7Y05ebv6QU .task.clickable{cursor:pointer}#mermaid-svg-gXFUFE7Y05ebv6QU .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-gXFUFE7Y05ebv6QU .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-gXFUFE7Y05ebv6QU .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-gXFUFE7Y05ebv6QU .taskText0,#mermaid-svg-gXFUFE7Y05ebv6QU .taskText1,#mermaid-svg-gXFUFE7Y05ebv6QU .taskText2,#mermaid-svg-gXFUFE7Y05ebv6QU .taskText3{fill:#fff}#mermaid-svg-gXFUFE7Y05ebv6QU .task0,#mermaid-svg-gXFUFE7Y05ebv6QU .task1,#mermaid-svg-gXFUFE7Y05ebv6QU .task2,#mermaid-svg-gXFUFE7Y05ebv6QU .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-gXFUFE7Y05ebv6QU .taskTextOutside0,#mermaid-svg-gXFUFE7Y05ebv6QU .taskTextOutside2{fill:#000}#mermaid-svg-gXFUFE7Y05ebv6QU .taskTextOutside1,#mermaid-svg-gXFUFE7Y05ebv6QU .taskTextOutside3{fill:#000}#mermaid-svg-gXFUFE7Y05ebv6QU .active0,#mermaid-svg-gXFUFE7Y05ebv6QU .active1,#mermaid-svg-gXFUFE7Y05ebv6QU .active2,#mermaid-svg-gXFUFE7Y05ebv6QU .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-gXFUFE7Y05ebv6QU .activeText0,#mermaid-svg-gXFUFE7Y05ebv6QU .activeText1,#mermaid-svg-gXFUFE7Y05ebv6QU .activeText2,#mermaid-svg-gXFUFE7Y05ebv6QU .activeText3{fill:#000 !important}#mermaid-svg-gXFUFE7Y05ebv6QU .done0,#mermaid-svg-gXFUFE7Y05ebv6QU .done1,#mermaid-svg-gXFUFE7Y05ebv6QU .done2,#mermaid-svg-gXFUFE7Y05ebv6QU .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-gXFUFE7Y05ebv6QU .doneText0,#mermaid-svg-gXFUFE7Y05ebv6QU .doneText1,#mermaid-svg-gXFUFE7Y05ebv6QU .doneText2,#mermaid-svg-gXFUFE7Y05ebv6QU .doneText3{fill:#000 !important}#mermaid-svg-gXFUFE7Y05ebv6QU .crit0,#mermaid-svg-gXFUFE7Y05ebv6QU .crit1,#mermaid-svg-gXFUFE7Y05ebv6QU .crit2,#mermaid-svg-gXFUFE7Y05ebv6QU .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-gXFUFE7Y05ebv6QU .activeCrit0,#mermaid-svg-gXFUFE7Y05ebv6QU .activeCrit1,#mermaid-svg-gXFUFE7Y05ebv6QU .activeCrit2,#mermaid-svg-gXFUFE7Y05ebv6QU .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-gXFUFE7Y05ebv6QU .doneCrit0,#mermaid-svg-gXFUFE7Y05ebv6QU .doneCrit1,#mermaid-svg-gXFUFE7Y05ebv6QU .doneCrit2,#mermaid-svg-gXFUFE7Y05ebv6QU .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-gXFUFE7Y05ebv6QU .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-gXFUFE7Y05ebv6QU .milestoneText{font-style:italic}#mermaid-svg-gXFUFE7Y05ebv6QU .doneCritText0,#mermaid-svg-gXFUFE7Y05ebv6QU .doneCritText1,#mermaid-svg-gXFUFE7Y05ebv6QU .doneCritText2,#mermaid-svg-gXFUFE7Y05ebv6QU .doneCritText3{fill:#000 !important}#mermaid-svg-gXFUFE7Y05ebv6QU .activeCritText0,#mermaid-svg-gXFUFE7Y05ebv6QU .activeCritText1,#mermaid-svg-gXFUFE7Y05ebv6QU .activeCritText2,#mermaid-svg-gXFUFE7Y05ebv6QU .activeCritText3{fill:#000 !important}#mermaid-svg-gXFUFE7Y05ebv6QU .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-gXFUFE7Y05ebv6QU g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-gXFUFE7Y05ebv6QU g.classGroup text .title{font-weight:bolder}#mermaid-svg-gXFUFE7Y05ebv6QU g.clickable{cursor:pointer}#mermaid-svg-gXFUFE7Y05ebv6QU g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-gXFUFE7Y05ebv6QU g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-gXFUFE7Y05ebv6QU .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-gXFUFE7Y05ebv6QU .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-gXFUFE7Y05ebv6QU .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-gXFUFE7Y05ebv6QU .dashed-line{stroke-dasharray:3}#mermaid-svg-gXFUFE7Y05ebv6QU #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-gXFUFE7Y05ebv6QU #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-gXFUFE7Y05ebv6QU #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-gXFUFE7Y05ebv6QU #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-gXFUFE7Y05ebv6QU #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-gXFUFE7Y05ebv6QU #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-gXFUFE7Y05ebv6QU #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-gXFUFE7Y05ebv6QU #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-gXFUFE7Y05ebv6QU .commit-id,#mermaid-svg-gXFUFE7Y05ebv6QU .commit-msg,#mermaid-svg-gXFUFE7Y05ebv6QU .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-gXFUFE7Y05ebv6QU .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-gXFUFE7Y05ebv6QU .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-gXFUFE7Y05ebv6QU g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-gXFUFE7Y05ebv6QU g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-gXFUFE7Y05ebv6QU g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-gXFUFE7Y05ebv6QU g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-gXFUFE7Y05ebv6QU g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-gXFUFE7Y05ebv6QU g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-gXFUFE7Y05ebv6QU .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-gXFUFE7Y05ebv6QU .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-gXFUFE7Y05ebv6QU .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-gXFUFE7Y05ebv6QU .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-gXFUFE7Y05ebv6QU .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-gXFUFE7Y05ebv6QU .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-gXFUFE7Y05ebv6QU .edgeLabel text{fill:#333}#mermaid-svg-gXFUFE7Y05ebv6QU .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-gXFUFE7Y05ebv6QU .node circle.state-start{fill:black;stroke:black}#mermaid-svg-gXFUFE7Y05ebv6QU .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-gXFUFE7Y05ebv6QU #statediagram-barbEnd{fill:#9370db}#mermaid-svg-gXFUFE7Y05ebv6QU .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-gXFUFE7Y05ebv6QU .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-gXFUFE7Y05ebv6QU .statediagram-state .divider{stroke:#9370db}#mermaid-svg-gXFUFE7Y05ebv6QU .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-gXFUFE7Y05ebv6QU .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-gXFUFE7Y05ebv6QU .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-gXFUFE7Y05ebv6QU .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-gXFUFE7Y05ebv6QU .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-gXFUFE7Y05ebv6QU .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-gXFUFE7Y05ebv6QU .note-edge{stroke-dasharray:5}#mermaid-svg-gXFUFE7Y05ebv6QU .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-gXFUFE7Y05ebv6QU .error-icon{fill:#522}#mermaid-svg-gXFUFE7Y05ebv6QU .error-text{fill:#522;stroke:#522}#mermaid-svg-gXFUFE7Y05ebv6QU .edge-thickness-normal{stroke-width:2px}#mermaid-svg-gXFUFE7Y05ebv6QU .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-gXFUFE7Y05ebv6QU .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-gXFUFE7Y05ebv6QU .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-gXFUFE7Y05ebv6QU .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-gXFUFE7Y05ebv6QU .marker{fill:#333}#mermaid-svg-gXFUFE7Y05ebv6QU .marker.cross{stroke:#333}:root { --mermaid-font-family: "trebuchet ms", verdana, arial;} #mermaid-svg-gXFUFE7Y05ebv6QU {color: rgba(0, 0, 0, 0.75);font: ;}

yes
no
true
false
开始
View.dispatchTouchEvent
onTouchListener == null
onTouchEvent
结束
OnTouchListener.onTouch
  • View.dispatchTouchEvent类图:
#mermaid-svg-hnfsCkhtKJbHevM5 .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-hnfsCkhtKJbHevM5 .label text{fill:#333}#mermaid-svg-hnfsCkhtKJbHevM5 .node rect,#mermaid-svg-hnfsCkhtKJbHevM5 .node circle,#mermaid-svg-hnfsCkhtKJbHevM5 .node ellipse,#mermaid-svg-hnfsCkhtKJbHevM5 .node polygon,#mermaid-svg-hnfsCkhtKJbHevM5 .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-hnfsCkhtKJbHevM5 .node .label{text-align:center;fill:#333}#mermaid-svg-hnfsCkhtKJbHevM5 .node.clickable{cursor:pointer}#mermaid-svg-hnfsCkhtKJbHevM5 .arrowheadPath{fill:#333}#mermaid-svg-hnfsCkhtKJbHevM5 .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-hnfsCkhtKJbHevM5 .flowchart-link{stroke:#333;fill:none}#mermaid-svg-hnfsCkhtKJbHevM5 .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-hnfsCkhtKJbHevM5 .edgeLabel rect{opacity:0.9}#mermaid-svg-hnfsCkhtKJbHevM5 .edgeLabel span{color:#333}#mermaid-svg-hnfsCkhtKJbHevM5 .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-hnfsCkhtKJbHevM5 .cluster text{fill:#333}#mermaid-svg-hnfsCkhtKJbHevM5 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-hnfsCkhtKJbHevM5 .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-hnfsCkhtKJbHevM5 text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-hnfsCkhtKJbHevM5 .actor-line{stroke:grey}#mermaid-svg-hnfsCkhtKJbHevM5 .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-hnfsCkhtKJbHevM5 .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-hnfsCkhtKJbHevM5 #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-hnfsCkhtKJbHevM5 .sequenceNumber{fill:#fff}#mermaid-svg-hnfsCkhtKJbHevM5 #sequencenumber{fill:#333}#mermaid-svg-hnfsCkhtKJbHevM5 #crosshead path{fill:#333;stroke:#333}#mermaid-svg-hnfsCkhtKJbHevM5 .messageText{fill:#333;stroke:#333}#mermaid-svg-hnfsCkhtKJbHevM5 .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-hnfsCkhtKJbHevM5 .labelText,#mermaid-svg-hnfsCkhtKJbHevM5 .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-hnfsCkhtKJbHevM5 .loopText,#mermaid-svg-hnfsCkhtKJbHevM5 .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-hnfsCkhtKJbHevM5 .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-hnfsCkhtKJbHevM5 .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-hnfsCkhtKJbHevM5 .noteText,#mermaid-svg-hnfsCkhtKJbHevM5 .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-hnfsCkhtKJbHevM5 .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-hnfsCkhtKJbHevM5 .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-hnfsCkhtKJbHevM5 .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-hnfsCkhtKJbHevM5 .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-hnfsCkhtKJbHevM5 .section{stroke:none;opacity:0.2}#mermaid-svg-hnfsCkhtKJbHevM5 .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-hnfsCkhtKJbHevM5 .section2{fill:#fff400}#mermaid-svg-hnfsCkhtKJbHevM5 .section1,#mermaid-svg-hnfsCkhtKJbHevM5 .section3{fill:#fff;opacity:0.2}#mermaid-svg-hnfsCkhtKJbHevM5 .sectionTitle0{fill:#333}#mermaid-svg-hnfsCkhtKJbHevM5 .sectionTitle1{fill:#333}#mermaid-svg-hnfsCkhtKJbHevM5 .sectionTitle2{fill:#333}#mermaid-svg-hnfsCkhtKJbHevM5 .sectionTitle3{fill:#333}#mermaid-svg-hnfsCkhtKJbHevM5 .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-hnfsCkhtKJbHevM5 .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-hnfsCkhtKJbHevM5 .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-hnfsCkhtKJbHevM5 .grid path{stroke-width:0}#mermaid-svg-hnfsCkhtKJbHevM5 .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-hnfsCkhtKJbHevM5 .task{stroke-width:2}#mermaid-svg-hnfsCkhtKJbHevM5 .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-hnfsCkhtKJbHevM5 .taskText:not([font-size]){font-size:11px}#mermaid-svg-hnfsCkhtKJbHevM5 .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-hnfsCkhtKJbHevM5 .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-hnfsCkhtKJbHevM5 .task.clickable{cursor:pointer}#mermaid-svg-hnfsCkhtKJbHevM5 .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-hnfsCkhtKJbHevM5 .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-hnfsCkhtKJbHevM5 .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-hnfsCkhtKJbHevM5 .taskText0,#mermaid-svg-hnfsCkhtKJbHevM5 .taskText1,#mermaid-svg-hnfsCkhtKJbHevM5 .taskText2,#mermaid-svg-hnfsCkhtKJbHevM5 .taskText3{fill:#fff}#mermaid-svg-hnfsCkhtKJbHevM5 .task0,#mermaid-svg-hnfsCkhtKJbHevM5 .task1,#mermaid-svg-hnfsCkhtKJbHevM5 .task2,#mermaid-svg-hnfsCkhtKJbHevM5 .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-hnfsCkhtKJbHevM5 .taskTextOutside0,#mermaid-svg-hnfsCkhtKJbHevM5 .taskTextOutside2{fill:#000}#mermaid-svg-hnfsCkhtKJbHevM5 .taskTextOutside1,#mermaid-svg-hnfsCkhtKJbHevM5 .taskTextOutside3{fill:#000}#mermaid-svg-hnfsCkhtKJbHevM5 .active0,#mermaid-svg-hnfsCkhtKJbHevM5 .active1,#mermaid-svg-hnfsCkhtKJbHevM5 .active2,#mermaid-svg-hnfsCkhtKJbHevM5 .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-hnfsCkhtKJbHevM5 .activeText0,#mermaid-svg-hnfsCkhtKJbHevM5 .activeText1,#mermaid-svg-hnfsCkhtKJbHevM5 .activeText2,#mermaid-svg-hnfsCkhtKJbHevM5 .activeText3{fill:#000 !important}#mermaid-svg-hnfsCkhtKJbHevM5 .done0,#mermaid-svg-hnfsCkhtKJbHevM5 .done1,#mermaid-svg-hnfsCkhtKJbHevM5 .done2,#mermaid-svg-hnfsCkhtKJbHevM5 .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-hnfsCkhtKJbHevM5 .doneText0,#mermaid-svg-hnfsCkhtKJbHevM5 .doneText1,#mermaid-svg-hnfsCkhtKJbHevM5 .doneText2,#mermaid-svg-hnfsCkhtKJbHevM5 .doneText3{fill:#000 !important}#mermaid-svg-hnfsCkhtKJbHevM5 .crit0,#mermaid-svg-hnfsCkhtKJbHevM5 .crit1,#mermaid-svg-hnfsCkhtKJbHevM5 .crit2,#mermaid-svg-hnfsCkhtKJbHevM5 .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-hnfsCkhtKJbHevM5 .activeCrit0,#mermaid-svg-hnfsCkhtKJbHevM5 .activeCrit1,#mermaid-svg-hnfsCkhtKJbHevM5 .activeCrit2,#mermaid-svg-hnfsCkhtKJbHevM5 .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-hnfsCkhtKJbHevM5 .doneCrit0,#mermaid-svg-hnfsCkhtKJbHevM5 .doneCrit1,#mermaid-svg-hnfsCkhtKJbHevM5 .doneCrit2,#mermaid-svg-hnfsCkhtKJbHevM5 .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-hnfsCkhtKJbHevM5 .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-hnfsCkhtKJbHevM5 .milestoneText{font-style:italic}#mermaid-svg-hnfsCkhtKJbHevM5 .doneCritText0,#mermaid-svg-hnfsCkhtKJbHevM5 .doneCritText1,#mermaid-svg-hnfsCkhtKJbHevM5 .doneCritText2,#mermaid-svg-hnfsCkhtKJbHevM5 .doneCritText3{fill:#000 !important}#mermaid-svg-hnfsCkhtKJbHevM5 .activeCritText0,#mermaid-svg-hnfsCkhtKJbHevM5 .activeCritText1,#mermaid-svg-hnfsCkhtKJbHevM5 .activeCritText2,#mermaid-svg-hnfsCkhtKJbHevM5 .activeCritText3{fill:#000 !important}#mermaid-svg-hnfsCkhtKJbHevM5 .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-hnfsCkhtKJbHevM5 g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-hnfsCkhtKJbHevM5 g.classGroup text .title{font-weight:bolder}#mermaid-svg-hnfsCkhtKJbHevM5 g.clickable{cursor:pointer}#mermaid-svg-hnfsCkhtKJbHevM5 g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-hnfsCkhtKJbHevM5 g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-hnfsCkhtKJbHevM5 .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-hnfsCkhtKJbHevM5 .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-hnfsCkhtKJbHevM5 .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-hnfsCkhtKJbHevM5 .dashed-line{stroke-dasharray:3}#mermaid-svg-hnfsCkhtKJbHevM5 #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-hnfsCkhtKJbHevM5 #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-hnfsCkhtKJbHevM5 #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-hnfsCkhtKJbHevM5 #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-hnfsCkhtKJbHevM5 #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-hnfsCkhtKJbHevM5 #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-hnfsCkhtKJbHevM5 #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-hnfsCkhtKJbHevM5 #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-hnfsCkhtKJbHevM5 .commit-id,#mermaid-svg-hnfsCkhtKJbHevM5 .commit-msg,#mermaid-svg-hnfsCkhtKJbHevM5 .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-hnfsCkhtKJbHevM5 .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-hnfsCkhtKJbHevM5 .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-hnfsCkhtKJbHevM5 g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-hnfsCkhtKJbHevM5 g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-hnfsCkhtKJbHevM5 g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-hnfsCkhtKJbHevM5 g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-hnfsCkhtKJbHevM5 g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-hnfsCkhtKJbHevM5 g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-hnfsCkhtKJbHevM5 .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-hnfsCkhtKJbHevM5 .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-hnfsCkhtKJbHevM5 .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-hnfsCkhtKJbHevM5 .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-hnfsCkhtKJbHevM5 .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-hnfsCkhtKJbHevM5 .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-hnfsCkhtKJbHevM5 .edgeLabel text{fill:#333}#mermaid-svg-hnfsCkhtKJbHevM5 .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-hnfsCkhtKJbHevM5 .node circle.state-start{fill:black;stroke:black}#mermaid-svg-hnfsCkhtKJbHevM5 .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-hnfsCkhtKJbHevM5 #statediagram-barbEnd{fill:#9370db}#mermaid-svg-hnfsCkhtKJbHevM5 .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-hnfsCkhtKJbHevM5 .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-hnfsCkhtKJbHevM5 .statediagram-state .divider{stroke:#9370db}#mermaid-svg-hnfsCkhtKJbHevM5 .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-hnfsCkhtKJbHevM5 .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-hnfsCkhtKJbHevM5 .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-hnfsCkhtKJbHevM5 .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-hnfsCkhtKJbHevM5 .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-hnfsCkhtKJbHevM5 .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-hnfsCkhtKJbHevM5 .note-edge{stroke-dasharray:5}#mermaid-svg-hnfsCkhtKJbHevM5 .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-hnfsCkhtKJbHevM5 .error-icon{fill:#522}#mermaid-svg-hnfsCkhtKJbHevM5 .error-text{fill:#522;stroke:#522}#mermaid-svg-hnfsCkhtKJbHevM5 .edge-thickness-normal{stroke-width:2px}#mermaid-svg-hnfsCkhtKJbHevM5 .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-hnfsCkhtKJbHevM5 .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-hnfsCkhtKJbHevM5 .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-hnfsCkhtKJbHevM5 .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-hnfsCkhtKJbHevM5 .marker{fill:#333}#mermaid-svg-hnfsCkhtKJbHevM5 .marker.cross{stroke:#333}:root { --mermaid-font-family: "trebuchet ms", verdana, arial;} #mermaid-svg-hnfsCkhtKJbHevM5 {color: rgba(0, 0, 0, 0.75);font: ;} ViewGroup +dispatchTouchEvent(MotionEvent ev) : boolean +onInterceptTouchEvent(MotionEvent ev) : boolean View +dispatchTouchEvent(MotionEvent ev) : boolean +onTouchEvent(MotionEvent ev) : boolean «interface» OnTouchListener onTouch(MotionEvent ev)

View.java

public boolean dispatchTouchEvent(MotionEvent event) {ListenerInfo li = mListenerInfo;if (li != null && li.mOnTouchListener != null && (mViewFlags & ENABLED_MASK) == ENABLED&& li.mOnTouchListener.onTouch(this, event)) {result = true;}if (!result && onTouchEvent(event)) {result = true;}
}

从源码中可以看出,OnTouchListener.onTouch的优先级会高于onTouchEvent

onTouchEvent是处理触摸事件时调用的,OnTouchListener.onTouch可以拦截这个触摸事件,跟ViewGroup.onInterceptTouchEvent有点像,只是它的条件比较多,而且不一定会执行。

(1)ViewGroup调用super.dispatchTouchEvent

如果此时的View.onTouchEvent是由ViewGroupsuper.dispatchTouchEvent触发的,那么当View.onTouchEvent返回TRUE时,这意味着触摸事件已经被消费;如果View.onTouchEvent返回FALSE时,这意味着触摸事件没有被消费,那么ViewGroup.dispatchTouchEvent就会返回FALSE,进而触发Activity.onTouchEvent

(2)View调用dispatchTouchEvent

如果此时的View.dispatchTouchEventView调用的话,那么就证明触摸事件已经分发到对应的子view上了。如果View.onTouchEvent返回TRUE,那么该事件被消费;如果View.onTouchEvent返回FALSE,那么会回到ViewGroup.dispatchTouchEvent中,要么继续遍历找到符合条件的子view派发事件,要么调用ViewGroup.onTouchEvent进行处理。如果是后者,如果ViewGroup.onTouchEvent返回TRUE,那么事件被消费;如果ViewGroup.onTouchEvent返回FALSE,那么就会回到Activity.dispatchTouchEvent,然后调用Activity.onTouchEvent


三、总结

事件分发的过程就是先从Activity.dispatchTouchEvent开始,然后到ViewGroup.dispatchTouchEvent。这时要先判断ViewGroup.onInterceptTouchEvent是否有拦截事件,如果有,事件交由ViewGroup.onTouchEvent处理;如果没有,事件交由View.dispatchTouchEvent处理。在View.dispatchTouchEvent中,如果不考虑OnTouchListener.onTouchEvent的话,就会调用View.onTouchEvent

在调用各种onTouchEvent的过程中,如果返回值为TRUE,就证明事件被消费;如果返回值为FALSE,除了Activity会视作事件被消费,其他的ViewGroupView都会视为事件未被消费,然后将事件交由Activity父viewonTouchEvent进行处理。

在调用各种dispatchTouchEvent的过程中,不考虑Activity,如果返回值为TRUE,意味着该事件被当前view或者子view消费了;如果返回值为FALSE,意味着事件未被消费,需要交由Activity父viewonTouchEvent进行处理。

note_44:事件分发相关推荐

  1. 介绍一下android的事件分发机制

    分发事件是指点击事件: 按下.滑动.抬起.取消(滑动超出控件边界时) 分发事件的组件: 也称为分发事件者,包括Activity.ViewGroup和View 事件分发的入口: Activity.dis ...

  2. ViewGroup的Touch事件分发(源码分析)

    Android中Touch事件的分发又分为View和ViewGroup的事件分发,View的touch事件分发相对比较简单,可参考 View的Touch事件分发(一.初步了解) View的Touch事 ...

  3. View的Touch事件分发(二.源码分析)

    Android中Touch事件的分发又分为View和ViewGroup的事件分发,先来看简单的View的touch事件分发. 主要分析View的dispatchTouchEvent()方法和onTou ...

  4. View的Touch事件分发(一.初步了解)

    Android中Touch事件的分发又分为View和ViewGroup的事件分发,先来看简单的View的touch事件分发. 一次完整的Touch事件序列为: ACTION_DOWN -> AC ...

  5. android 点击事件消费,Android View事件分发和消费源码简单理解

    Android View事件分发和消费源码简单理解 前言: 开发过程中觉得View事件这块是特别烧脑的,看了好久,才自认为看明白.中间上网查了下singwhatiwanna粉丝的读书笔记,有种茅塞顿开 ...

  6. android 事件冒泡,Android事件分发

    当用户触摸屏幕时,系统会对触摸事件做出相应的相应,这个事件会产生一个MotionEvent,系统根据一定的规则将其传递给View进行处理,这个过程就是事件分发机制了. 事件的传递分为两个阶段,即捕获阶 ...

  7. cocos2d JS 自定义事件分发器(接收与传递数据) eventManager

    简而言之,它不是由系统自动触发,而是人为的干涉 较多情况用于传递数据 var _listener1 = cc.EventListener.create({event: cc.EventListener ...

  8. View事件分发机制(源码 API27)

    1.什么是事件分发机制 当用户触摸屏幕时,会产生一个touch事件,这个touch事件(motionEvent)传递到某个具体的view处理的整个过程 用户触摸屏幕会产生一个事件流(ACTION_DO ...

  9. Android 事件分发 简单学

    为什么80%的码农都做不了架构师?>>>    本文地址:https://my.oschina.net/lifj/blog/1928132 Android 事件分发过程 网上有很多这 ...

最新文章

  1. MYSQL两个数据库字符集保持一致问题
  2. 【计算机视觉】OpenCV的最近邻开源库FLANN
  3. codeforces1454 F. Array Partition
  4. 前台一键备份数据库+PHP实现方式
  5. 图论 —— 最短路 —— Floyd 算法
  6. Java面试之五大框架的理解
  7. python查找excel中字符串_在Python问题中通过Excel搜索字符串/正则表达式
  8. Eclipse javax.servlet.jsp.PageContext cannot be resolved to a type 错误解决办法
  9. 在线文本字符串批量替换工具
  10. golang语言os.Stat()用法及功能
  11. amp;#9733;一名“标题党”自我修炼的10…
  12. 如何使用代码获取电脑内存_代码实战 | 如何在 Android 开发中使用协程
  13. 20120912新工作感想
  14. 杜绝采购欺诈:利用SRM系统监控采购计划
  15. oracle_用户与概要文件
  16. 阵列服务器怎么拆硬盘盒,磁盘阵列硬盘盒拆解和安装,很详细
  17. ODC预端接光纤配线箱
  18. css清除浮动大全,共8种方法。
  19. php导入表格 出错,PHPExcel导入数据出现问题
  20. ZSC 1306: 沼跃鱼早已看穿了一切 题解

热门文章

  1. 卷积神经网络中感受野计算
  2. 谈谈TL431与AZ431代换通用问题(个人经验)
  3. 电脑网络连接正常 QQ、微信、钉钉网络正常,但是浏览器打不开网页?
  4. 台式计算机无法连接网络,终于理解台式电脑怎么连接网络
  5. 目录扫描Dirbuster的用法详解
  6. 信息收集之目录扫描-dirbuster
  7. [Python]网络编程基础
  8. LibROSA库提取MFCC特征的过程解析
  9. mysql econnreset_节点js ECONNRESET
  10. 王者s19服务器维护到什么时候,王者荣耀S19新版本玄雍危机维护到几点 王者荣耀今天几点维护完...