add depth to scrolling the viewpager
This commit is contained in:
parent
77e25ae9a7
commit
1d76f572f2
1 changed files with 26 additions and 0 deletions
|
@ -72,6 +72,7 @@ public class ViewPagerActivity extends AppCompatActivity
|
|||
pager.setCurrentItem(pos);
|
||||
pager.addOnPageChangeListener(this);
|
||||
pager.setOnTouchListener(this);
|
||||
pager.setPageTransformer(true, new DepthPageTransformer());
|
||||
|
||||
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(this);
|
||||
updateActionbarTitle();
|
||||
|
@ -376,4 +377,29 @@ public class ViewPagerActivity extends AppCompatActivity
|
|||
super.onPause();
|
||||
deleteFile();
|
||||
}
|
||||
|
||||
public class DepthPageTransformer implements ViewPager.PageTransformer {
|
||||
private static final float MIN_SCALE = 0.75f;
|
||||
|
||||
public void transformPage(View view, float position) {
|
||||
int pageWidth = view.getWidth();
|
||||
|
||||
if (position < -1) {
|
||||
view.setAlpha(0);
|
||||
} else if (position <= 0) {
|
||||
view.setAlpha(1);
|
||||
view.setTranslationX(0);
|
||||
view.setScaleX(1);
|
||||
view.setScaleY(1);
|
||||
} else if (position <= 1) {
|
||||
view.setAlpha(1 - position);
|
||||
view.setTranslationX(pageWidth * -position);
|
||||
float scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position));
|
||||
view.setScaleX(scaleFactor);
|
||||
view.setScaleY(scaleFactor);
|
||||
} else {
|
||||
view.setAlpha(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue