viewPager的OnPageChangeListener监听器的方法调用顺序

mviewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
          Log.d("测试代码", "onPageScrolled滑动中" + position);
         }

    @Override
    public void onPageSelected(int position) {
        Log.d("测试代码", "onPageSelected选中了" + position);
      
    }


    @Override
    public void onPageScrollStateChanged(int state) {

        if (state == ViewPager.SCROLL_STATE_DRAGGING) {
            //正在滑动   pager处于正在拖拽中

            Log.d("测试代码", "onPageScrollStateChanged=======正在滑动" + "SCROLL_STATE_DRAGGING");

        } else if (state == ViewPager.SCROLL_STATE_SETTLING) {
            //pager正在自动沉降,相当于松手后,pager恢复到一个完整pager的过程
            Log.d("测试代码", "onPageScrollStateChanged=======自动沉降" + "SCROLL_STATE_SETTLING");

        } else if (state == ViewPager.SCROLL_STATE_IDLE) {
            //空闲状态  pager处于空闲状态
            Log.d("测试代码", "onPageScrollStateChanged=======空闲状态" + "SCROLL_STATE_IDLE");
        }


    }
});

Log日志打印如下

09-14 16:02:18.577  13543-13543/com.football.app D/测试代码﹕ onPageScrollStateChanged=======正在滑动SCROLL_STATE_DRAGGING
09-14 16:02:18.577  13543-13543/com.football.app D/测试代码﹕ onPageScrolled滑动中0
09-14 16:02:18.591  13543-13543/com.football.app D/测试代码﹕ onPageScrolled滑动中0
09-14 16:02:18.607  13543-13543/com.football.app D/测试代码﹕ onPageScrolled滑动中0
09-14 16:02:18.615  13543-13543/com.football.app D/测试代码﹕ onPageScrollStateChanged=======自动沉降SCROLL_STATE_SETTLING
09-14 16:02:18.615  13543-13543/com.football.app D/测试代码﹕ onPageSelected1
09-14 16:02:18.624  13543-13543/com.football.app D/测试代码﹕ onPageScrolled滑动中0
09-14 16:02:18.641  13543-13543/com.football.app D/测试代码﹕ onPageScrolled滑动中0
09-14 16:02:18.658  13543-13543/com.football.app D/测试代码﹕ onPageScrolled滑动中0
09-14 16:02:18.675  13543-13543/com.football.app D/测试代码﹕ onPageScrolled滑动中0
09-14 16:02:18.691  13543-13543/com.football.app D/测试代码﹕ onPageScrolled滑动中0
09-14 16:02:18.709  13543-13543/com.football.app D/测试代码﹕ onPageScrolled滑动中0
09-14 16:02:18.726  13543-13543/com.football.app D/测试代码﹕ onPageScrolled滑动中0
09-14 16:02:18.743  13543-13543/com.football.app D/测试代码﹕ onPageScrolled滑动中0
09-14 16:02:18.760  13543-13543/com.football.app D/测试代码﹕ onPageScrolled滑动中0
09-14 16:02:18.777  13543-13543/com.football.app D/测试代码﹕ onPageScrolled滑动中0
09-14 16:02:18.794  13543-13543/com.football.app D/测试代码﹕ onPageScrolled滑动中0
09-14 16:02:18.811  13543-13543/com.football.app D/测试代码﹕ onPageScrolled滑动中0
09-14 16:02:18.828  13543-13543/com.football.app D/测试代码﹕ onPageScrolled滑动中0
09-14 16:02:18.845  13543-13543/com.football.app D/测试代码﹕ onPageScrolled滑动中1
09-14 16:02:18.946  13543-13543/com.football.app D/测试代码﹕ onPageScrollStateChanged=======空闲状态SCROLL_STATE_IDLE

 

 

 

通过日志 得出来  ViewPager滑动的时候  回调的方法顺序为  

  1. onPageScrollStateChanged()// state == ViewPager.SCROLL_STATE_DRAGGING  正在滑动状态

  2. onPageScrolled()  //滑动状态

  3. onPageScrollStateChanged() // state ==SCROLL_STATE_SETTLING  自动沉降状态

  4. onPageSelected() // 选中状态

  5. onPageScrolled()  //滑动状态

  6. onPageScrollStateChanged()  //state==SCROLL_STATE_IDLE   空闲状态  滑动结束

你可能感兴趣的:(viewPager的OnPageChangeListener监听器的方法调用顺序)