时间:2021-01-02 15:12:10 | 栏目:Android代码 | 点击:次
实例如下:
//记录上一次滑动的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) { } });