Skip to content

Instantly share code, notes, and snippets.

Created August 25, 2014 13:35
Show Gist options
  • Save anonymous/d532d41fa01c02a65782 to your computer and use it in GitHub Desktop.
Save anonymous/d532d41fa01c02a65782 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);
}
}
}
Copy link

ghost commented Oct 20, 2016

Jitter effect can be canceled when you reach the border?

@ericksprengel
Copy link

Should set alpha to 1?
I tried it and the views out of the current page are overlaping the current page.
I worked changing setAlpha(1) to setAlpha(0).

Thanks for this gist. <3

@Saadmohmmad
Copy link

hey bro what is dummyImageView this code

@adiga-maf
Copy link

hey bro what is dummyImageView this code

You can declare it before int pageWidth = view.getWidth(); as:
View dummyImageView = view.findViewById(R.id.image);

@shrikantingole08
Copy link

hii if i want use a dynamic image then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment