ViewPager判断是向左划还是右划的实例

实例如下:

//记录上一次滑动的positionOffsetPixels值
  private int lastValue = -1;
   private boolean isLeft = true;


 mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
      if (positionOffset != 0) {
        if (lastValue >= positionOffsetPixels) {
          //右滑
          isLeft = false;
        } else if (lastValue < positionOffsetPixels) {
          //左滑
          isLeft = true;
        }
        setIndiactorView(positionOffset,isLeft);
      }
      lastValue = positionOffsetPixels;

    }

    @Override
    public void onPageSelected(int position) {
      if (isLeft){
        Log.e("onPageScrolled","--->左划");
      }else {
        Log.e("onPageScrolled","--->右划");

      }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
  });

以上这篇ViewPager判断是向左划还是右划的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持呐喊教程。