有一个视图寻呼机,并使用了DepthPageTransformer。
mViewPager.setPageTransformer(false, new DepthPageTransformer());
DepthPageTransformer代码:
public class DepthPageTransformer implements PageTransformer {
private static float MIN_SCALE = 0.5f;
@Override
public void transformPage(View view, float position) {
/**
* [-1,0]Use the default slide transition when moving to the left page
* (0,1] Use the default slide transition when moving to the right page
* (1,+Infinity] This page is way off-screen to the right.
* [-Infinity,-1) This page is way off-screen to the left.
*/
int pageWidth = view.getWidth();
if (position > 1){
view.setAlpha(0);
view.setTranslationX(0);
}
else if (position > 0){
view.setAlpha(1);
view.setTranslationX(0);
view.setScaleX(1);
view.setScaleY(1);
}
else if (position >= -1){
view.setAlpha(1);
view.setTranslationX(pageWidth * -position);
// Scale the page down (between MIN_SCALE and 1)
float scaleFactor = MIN_SCALE + (1 - MIN_SCALE)
* (1 - Math.abs(position));
view.setScaleX(scaleFactor);
view.setScaleY(scaleFactor);
}
else{
view.setAlpha(0);
view.setScaleX(1);
view.setScaleY(1);
}
}
}
滚动视图寻呼机时会发生这种情况:所有片段都消失了。或者显示唯一的后面片段,比例为0.5,但前面的片段消失了,所以我们可以在屏幕上看到一个小片段。