Reputation: 896
I need to synchronize scrolling in two viewpagers.
Here some relevant code:
super.onTouchEvent(ev);
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
mViewPager.beginFakeDrag();
return true;
case MotionEvent.ACTION_MOVE:
mViewPager.fakeDragBy(mViewPager.getScrollX()-getScrollX());
return true;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
mViewPager.endFakeDrag();
return true;
default:
break;
}
return mViewPager.onTouchEvent(ev);
I`m getting touch event, and scrolling the second view by the same amount. But one thing I can't manage is to disable or handle fling similarly, I mean short fast gestrue which automaticaly makes scroll jump to next page.
Structure is -ViewPagerNavigator- -ViewPagerMenu-
How do I make fling in it to work on menu pager, or just disable it?
Upvotes: 3
Views: 3545
Reputation:
You can Check Out my answer here
Synchronizing two ViewPagers using OnPageChangeListener
You can also set different PageTransformers on these as well.
Upvotes: 0
Reputation: 45493
As per earlier commment:
I'm not sure it'll make a difference, but have you played around with the ViewPager.OnPageChangeListener
interface? In stead of capturing the touch event directly, I imagine you could use the onPageScrolled(...)
method and the passed in offset. For flings you might be able to get away with onPageSelected(...)
.
Upvotes: 1