Created
March 24, 2016 07:12
-
-
Save shau-lok/f962ecae14c370006d5b to your computer and use it in GitHub Desktop.
viewpager pageTransformer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DepthPageTransformer implements ViewPager.PageTransformer { | |
public static final float MIN_SCALE = 0.75f; | |
@Override | |
public void transformPage(View page, float position) { | |
int pageWidth = page.getWidth(); | |
if (position < -1) { | |
page.setAlpha(0); | |
} else if (position <= 0) { | |
page.setAlpha(1); | |
page.setTranslationX(0); | |
page.setScaleX(1); | |
page.setScaleY(1); | |
} else if (position <= 1) { | |
page.setAlpha(1 - position); | |
page.setTranslationX(pageWidth * -position); | |
float scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position)); | |
page.setScaleX(scaleFactor); | |
page.setScaleY(scaleFactor); | |
} else { | |
page.setAlpha(0); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment