Android事件分發總結

2021-08-27 08:25:55 字數 734 閱讀 4722

dispatchtouchevent() 返回true 消費事件

dispatchtouchevent() 返回false 不分發事件 由上層ontouchevent()處理

dispatchtouchevent() 返回super 預設邏輯向下分發事件

ontouchevent() 返回true 消費事件

ontouchevent() 返回false 向上回溯事件,交由上層ontouchevent()處理

ontouchevent() 返回super 預設邏輯向上回溯事件,交由上層ontouchevent()處理

onintercepttouchevent() 返回true 攔截事件,交由攔截該事件的viewgroup的ontouchevent() 處理。

onintercepttouchevent() 返回false 不攔截事件,向下執行子view的dispatchtouchevent()。

onintercepttouchevent() 返回super 預設邏輯不攔截事件,向下執行子view的dispatchtouchevent()。

特例activity 由於activity是事件的最上層

dispatchtouchevent() 返回false 直接消費處理

ontouchevent() 返回false 事件消失

Android事件分發總結

1.dispatchtouchevent是處理觸控事件分發,android中所有的事件都必須經過這個方法的分發,然後決定是自身消費當前事件還是繼續往下分發給子控制項處理。返回true表示不繼續分發,事件沒有被消費。返回false則繼續往下分發,如果是viewgroup則分發給oninterceptt...

Android 事件分發

touch 事件的分發和消費機制dispatchtouchevent onintercepttouchevent 和ontouchevent dispatchtouchevent 事件分發 true 事件會分發給當前view 並由dispatchtouchevent 方法消費,同時停止向下傳 fal...

Android事件分發

android 中與 touch 事件相關的方法包括 dispatchtouchevent motionevent ev onintercepttouchevent motionevent ev ontouchevent motionevent ev 能夠響應這些方法的控制項包括 viewgroup...