Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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(0);
} else if (position <= 1) { // [-1,1]
mBlur.setTranslationX((float) (-(1 - position) * 0.5 * pageWidth));
mBlurLabel.setTranslationX((float) (-(1 - position) * 0.5 * pageWidth));
mDim.setTranslationX((float) (-(1 - position) * pageWidth));
mDimLabel.setTranslationX((float) (-(1 - position) * pageWidth));
mCheck.setTranslationX((float) (-(1 - position) * 1.5 * pageWidth));
mDoneButton.setTranslationX((float) (-(1 - position) * 1.7 * pageWidth));
// The 0.5, 1.5, 1.7 values you see here are what makes the view move in a different speed.
// The bigger the number, the faster the view will translate.
// The result float is preceded by a minus because the views travel in the opposite direction of the movement.
mFirstColor.setTranslationX((position) * (pageWidth / 4));
mSecondColor.setTranslationX((position) * (pageWidth / 1));
mTint.setTranslationX((position) * (pageWidth / 2));
mDesaturate.setTranslationX((position) * (pageWidth / 1));
// This is another way to do it
} else { // (1,+Infinity]
// This page is way off-screen to the right.
view.setAlpha(0);
}
}
@mindshifter

This comment has been minimized.

Copy link

@mindshifter mindshifter commented Dec 15, 2014

Hi, how do you get the mBlur, mDim, and other per view elements ?

@eesa1980

This comment has been minimized.

Copy link

@eesa1980 eesa1980 commented Dec 15, 2014

@mindshifter

view.findViewById(the-view-you-require) should hopefully work for you.

@an631ac

This comment has been minimized.

Copy link

@an631ac an631ac commented Feb 17, 2015

Not animating with my viewpager that triggers by button click. How can I used this? Thanks

@udayharihar007cs

This comment has been minimized.

Copy link

@udayharihar007cs udayharihar007cs commented Apr 13, 2015

Not much clear , can you create a proper working example and upload it.

@orlytops

This comment has been minimized.

Copy link

@orlytops orlytops commented Jun 9, 2015

how can you get the views in each fragment?

@Jugalkishorocs

This comment has been minimized.

Copy link

@Jugalkishorocs Jugalkishorocs commented Mar 1, 2017

Not much clear , can you create a proper working example and upload it.

@abiemann

This comment has been minimized.

Copy link

@abiemann abiemann commented Mar 17, 2017

it seems like the whole public class YourTransformer implements ViewPager.PageTransformer would have been useful

@sahilk01

This comment has been minimized.

Copy link

@sahilk01 sahilk01 commented Jun 4, 2020

where to call this function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.