认识 ViewPager position

来源:互联网 发布:怎么更改mac管理员名称 编辑:程序博客网 时间:2024/06/01 08:22

首先要熟悉ViewPager .setOnPageChangeListener(new OnPageChangeListener()中的public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels)

position :
(currentIndex == 0 && position == 0) // 0->1
(currentIndex == 1 && position == 0) // 1->0
(currentIndex == 1 && position == 1) // 1->2
(currentIndex == 2 && position == 1) // 2->1
因此可以得到以下结论:
当界面向右滑动的时候:position等于currentIndex
当界面向左滑动的时候:position等于currentIndex - 1

positionOffset 滑动到下一页,[0,1)区间上变化;滑动到上一页:(1,0]区间上变化

positionOffsetPixels这个和positionOffset很像:滑动到下一页,[0,宽度)区间上变化;滑动到上一页:(宽度,0]区间上变化

0 0
原创粉丝点击