Android之ViewPager.PageTransformer
继承PageTransformer,滑动ViewPager,可以观察到
public abstract class AbsBaseViewPagerTransfer implements ViewPager.PageTransformer {
private static final UtilsLog lg = UtilsLog.getLogger(AbsBaseViewPagerTransfer.class.getSimpleName());
@Override
public void transformPage(View page, float position) {
lg.e("PageView:" + page + ",position:" + position);
if (position < -1 || position > 1) {
lg.e("划出界面外");
outOfEdge(page, position);
} else {
inOfEdge(page, position);
}
}
protected abstract void outOfEdge(View pageView, float position);
protected abstract void inOfEdge(View pageView, float position);
}
position代表的意义:
[-Infinity,-1) 已经从左边划出边界
(1,+Infinity] 已经从右边划出边界
[-1,1] 在可见范围内
当前页面从左边划出时(即ViewPager滑到下一页),position由0变为-1。
![](https://images2015.cnblogs.com/blog/781056/201608/781056-20160818105703046-1112192188.png)
当前页面从右边划出时(即ViewPager滑到上一页),position由0变为1。
![](https://images2015.cnblogs.com/blog/781056/201608/781056-20160818105705140-1849710635.png)