Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

two ViewPagers synchronized scrolling

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?

like image 867
Drake29a Avatar asked Apr 19 '26 21:04

Drake29a


1 Answers

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(...).

like image 171
MH. Avatar answered Apr 22 '26 12:04

MH.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!