I have a Gallery with an adapter which supplies it ScrollViews as its child views. I need to make sure that the touch events are handled correctly and as expected:
- When the user scrolls horizontally, the gallery scrolls horizontally.
- When the user scrolls vertically, the scroll view scrolls vertically.
- Both scrolls should never happen on the same gesture (the user must lift their finger to scroll the other view).
- Everything must scroll smoothly.
Without overriding any methods, the scroll view is the only thing that scrolls - the gallery never scrolls.
So I understand I need to use onInterceptTouchEvent(...) in the gallery to decide to take over a certain series of MotionEvents but I am unsure how to check if the touch is horizontal or vertical in nature.
I have tried solution provided by Warlax. It moved me forward but unfortunately it breaks normal gallery behavior in some rare cases. (For example it doesn't stop on touch while scrolling) So I did more research and came up with the following solution.
OK, after some major fiddling and logcat hacking, here's the solution: