0

Let's say I have a ViewPager that takes 50% of screen height and a simple View (or other component) that takes other half of my screen. When I swipe on the View component I want my interaction to be visible on the ViewPager as if I was swiping on the ViewPager itself.

Any ideas how to implement this? I have tried overriding onTouchEvent in the View and then triggering onTouchEvent in the ViewPager, but that did not seem to work.

brisky
  • 197
  • 1
  • 1
  • 14
  • If you can settle for swipes on the `View` triggering page changes in the `ViewPager`, just [call `setCurrentItem(index, true)`](http://developer.android.com/reference/android/support/v4/view/ViewPager.html#setCurrentItem%28int,%20boolean%29) on the `ViewPager` when you detect the gesture in the `View`. – CommonsWare Feb 07 '15 at 15:24
  • no, i want to see exact movement, setCurrentItem is not enough for me – brisky Feb 07 '15 at 15:29

2 Answers2

0

I found the solutions myself. Here is how to do it:

1) Create a custom Class for your View that is instance of ViewGroup and overrides onInterceptTouchEvent(). Make sure that children of this ViewGroup return true onTouchEvent().

More explanation here: onInterceptTouchEvent only gets ACTION_DOWN

2) Inside onInterceptTouchEvent(MotionEvent ev) you have to forward the event to viewPager by calling viewPager.dispatchTouchEvent(ev)

Community
  • 1
  • 1
brisky
  • 197
  • 1
  • 1
  • 14
0

You can use special methods in ViewPager class:

lobzik
  • 10,974
  • 1
  • 27
  • 32