I have a project using a ViewPager which works correctly:
I can page from view to view by flicking left and right.
On one page of the ViewPager, I have a custom view and I am trying to add below it another view (LinearLayout) that is touch sensitive and that will not “page” the ViewPager. Like this:
<LinearLayout >
<myView />
<LinearLayout> // The touch sensitive region
</LinearLayout>
</LinearLayout>
After my view has been inflated and added to the ViewPager, I call setOnTouchListener() to attach a listener to the internal LinearLayout. The listener returns “true”.
Unfortunateley when I move horizontally in that view, I move to another page.
The events I get are:
ACTION_DOWN, ACTION_MOVE (n times) and finally ACTION_CANCEL. Although I stayed within the view.
It seems that the event has gone up the view hierarchy and processed by the ViewPager.
Is there a logical explanation to this behaviour ?
I have found a workaround by intercepting events at the Activity level, overriding dispatchTouchEvent().
In there, I call super.dispatchTouchEvent() for processing all events unless the user is touching my touch sensitive view. I test if the user is on the correct page and at the right location. In that case I process the event myself.