Android - Intercept and pass on all touch events

后端 未结 5 1982
名媛妹妹
名媛妹妹 2021-02-02 15:47

I have an overlay ViewGroup that is the size of the screen which I want to use to show an effect when the user interacts with the app, but still passes the onTouch event to any

5条回答
  •  心在旅途
    2021-02-02 16:17

    As touch flows starting from root view to child views and after reaching the bottom most child it(touch) propagate back to root view while traversing all the OnTouchListener, if the actions consumable by child views return true and false for rest, then for the actions that you want to intercept can be written under OnTouchListner of those parents.

    Like if root view A has two child X and Y and you want to intercept swipe touch in A and want to propagate rest of touch to child views(X and Y) then override OnTouchListner of X and Y by returning false for swipe and true for rest. And override OnTouchListner of A with swipe returning true and rest returning false.

提交回复
热议问题