Skip to content

Instantly share code, notes, and snippets.

@feromakovi
Created August 15, 2014 13:31
Show Gist options
  • Save feromakovi/1654f6e2436a70fefd61 to your computer and use it in GitHub Desktop.
Save feromakovi/1654f6e2436a70fefd61 to your computer and use it in GitHub Desktop.
public class FilterPageTransformer implements ViewPager.PageTransformer {
public void transformPage(View view, float position) {
ImageView im = (ImageView) view;
int pageWidth = view.getWidth();
if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
im.setPadding(pageWidth, 0, 0, 0);
} else if (position <= 0) { // [-1,0]
// Use the default slide transition when moving to the left page
im.setPadding(-1 * Math.round(position * pageWidth) , 0, 0, 0);
} else if (position <= 1) { // (0,1]
log.d("position 0 1: " + position);
// Fade the page out.
// Counteract the default slide transition
im.setTranslationX(pageWidth * -position);
im.setPadding(0, 0, Math.round((1 - position) * pageWidth), 0);
} else { // (1,+Infinity]
// This page is way off-screen to the right.
//view.setAlpha(1);
im.setPadding(0, 0, pageWidth, 0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment