Skip to content

Instantly share code, notes, and snippets.

@iAviatorJose
Forked from anonymous/gist:d532d41fa01c02a65782
Created December 15, 2015 11:46

Revisions

  1. @invalid-email-address Anonymous created this gist Aug 25, 2014.
    23 changes: 23 additions & 0 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    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);
    }


    }
    }