How to know viewpager is scroll left or right?

前端 未结 13 1959
梦谈多话
梦谈多话 2020-12-13 06:18

I am using ViewPager (support library). I want to know every time the ViewPager change the visible page, it is scrolling left or right.

Please give me a solution. An

13条回答
  •  青春惊慌失措
    2020-12-13 07:19

    I solved the issue with this implementation. Hope it helps.

    public static final float EPSILON= 0.001f;
    
    @Override
    public void onPageScrolled(final int position, final float positionOffset, final int positionOffsetPixels) {
    
        // initial position (positionOffset == 0)
        if (positionOffset < EPSILON) {
            mIsRight = positionOffset < 0.5;
            return;
        }
    
        // code here
        if (mIsRight) {
        } else {
        }
    }
    

提交回复
热议问题