-
-
Save aaaliua/29c7934bd8b9b5d82833 to your computer and use it in GitHub Desktop.
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 ParallaxPageTransformer implements ViewPager.PageTransformer { | |
public void transformPage(View view, float position) { | |
int pageWidth = view.getWidth(); | |
if (position < -1) { // [-Infinity,-1) | |
// This page is way off-screen to the left. | |
view.setAlpha(1); | |
} else if (position <= 1) { // [-1,1] | |
dummyImageView.setTranslationX(-position * (pageWidth / 2)); //Half the normal speed | |
} else { // (1,+Infinity] | |
// This page is way off-screen to the right. | |
view.setAlpha(1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A great example is Yahoo’s Weather app, which became popular from this particular feature. Take a look at the gif below. The ViewPager’s pages slide normally, it’s the images that move with half the normal speed.