在上一家公司接手了乙個專案,由於介面互動的複雜性讓我花了很多時間去對android的事件分發與處理機制做了乙個相對比較深的研究。在此記錄一下。
事件返回
傳遞or消費
super.dispatchtouchevent
當前view的onintercepttouchevent
dispatchtouchevent
true
當前view的dispatchtouchevent消費,停止傳遞
false
事件來自activity,返回activity消費;事件來自父view,返回父view消費
super.onintercepttouchevent
事件攔截,交給當前view的ontouchevent消費
onintercepttouchevent
true
同上false
事件傳遞,交給子view的dispatchtouchevent
super.ontouchevent
事件返回上層view的ontouchevent處理
ontouchevent
true
接收消費
false
同super.ontouchevent
另view的監聽事件
事件返回
傳遞or消費
ontouch
true
ontouchevent不再執行
false
ontouchevent可執行
Android 事件分發
touch 事件的分發和消費機制dispatchtouchevent onintercepttouchevent 和ontouchevent dispatchtouchevent 事件分發 true 事件會分發給當前view 並由dispatchtouchevent 方法消費,同時停止向下傳 fal...
Android事件分發
android 中與 touch 事件相關的方法包括 dispatchtouchevent motionevent ev onintercepttouchevent motionevent ev ontouchevent motionevent ev 能夠響應這些方法的控制項包括 viewgroup...
Android事件分發
當使用者觸控螢幕時,系統會對觸控事件做出相應的相應,這個事件會產生乙個motionevent,系統根據一定的規則將其傳遞給view進行處理,這個過程就是事件分發機制了。事件的傳遞分為兩個階段,即捕獲階段和冒泡階段。捕獲階段 事件最先由最外層的view接收,然後依次向內層傳遞,直到傳遞到最小的view...