Catch Ontouch Event By Parent, Handle It And Pass To Children
I tried to understand how Android handle touch event and got a little bit confused. From what I understand touch event are send to the root view and pass down to the children. I ha
Solution 1:
My understanding is that it actually goes the other direction. The Child views get their event triggered first (sort of). The root view get's it's dispatchTouchEvent()
called, which propagates the event down to the children's onTouchEvent()
, and then, depending on whether they return true or false, the parent's onTouchEvent()
is called.
The normal solution for intercepting things like this is to override dispatchTouchEvent(MotionEvent ev)
in one's activity like so:
@OverridepublicbooleandispatchTouchEvent(MotionEvent ev) {
// Do your calcluationsreturnsuper.dispatchTouchEvent(ev);
}
The documentation for this one is here. Note that you can also override that method in any ViewGroup
(such as a FrameLayout
, etc)
Post a Comment for "Catch Ontouch Event By Parent, Handle It And Pass To Children"