Skip to content

Instantly share code, notes, and snippets.

@hardikamal
Forked from anonymous/gist:d532d41fa01c02a65782
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hardikamal/c4a01abf38802d98578f to your computer and use it in GitHub Desktop.
Save hardikamal/c4a01abf38802d98578f to your computer and use it in GitHub Desktop.
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