ViewPager判断是向左划还是右划的实例
时间: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) { } });
上一篇:Android开发之图形图像与动画(一)Paint和Canvas类学习
栏 目:Android代码
本文地址:http://www.codeinn.net/misctech/39450.html