When a child view is rotated, how does Android handle mapping touch points from the parent view to the child view?
Are the touch points put through a transformation at some point? If so, where?
I know that ViewGroups have methods like:
dispatchTouchEvent()
onInterceptTouchEvent()
onTouchEvent()
etc.
Is one of those responsible for taking the touch point within the parent view and transforming it to the local coordinate space of a subview?
I tried looking through the source code but couldn't really understand all the interactions.
All this stuff is performed in dispatchTouchEvent
method.
ViewGroup
iterates through it childrendispatchTouchEvent
MotionEvent
for each child (obtaining from pool to be more precise). See MotionEvent.obtain(MotionEvent)
MotionEvent
using child's top and left position (see getTop
and getLeft
methods).MotionEvent#transform
method (by taking inverse transformation matrix from child)MotionEvent
to child (and in case when this child is also ViewGroup
see pt.1)MotionEvent
(see MotionEvent#recycle
)And yes, as Delyan mentioned - transformation applies only for Honeycomb and newer versions of Android. On older versions just offset is performed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With