Skip to content

Instantly share code, notes, and snippets.

@mikeseif
Last active December 11, 2015 07:38
Show Gist options
  • Save mikeseif/4567399 to your computer and use it in GitHub Desktop.
Save mikeseif/4567399 to your computer and use it in GitHub Desktop.
SlideTransformer I'm using for a presentation, it scales the slides down smoothly by the scaleFactor given in the constructor. @TargetApi set to Honeycomb for lint, I haven't tested on Gingerbread yet and it may need tweaking. Instantiate after setting your adapter for the ViewPager with: mViewPager.setPageTransformer(true, new SlideTransformer(…
/**
* {@link android.support.v4.view.ViewPager.PageTransformer} to scale pages
* as they are slid left / right.
*
* @author michaelseifollahi
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private class SlideTransformer implements PageTransformer {
private final float fScaleFactor;
/**
* Constructor.
*
* @param scaleFactor float representing the scale amount to reduce the
* {@link android.view.View} by.
*/
public SlideTransformer(float scaleFactor) {
super();
fScaleFactor = scaleFactor;
}
@Override
public void transformPage(View page, float position) {
if (position >= 0) {
float scale = 1 - (fScaleFactor * position);
page.setScaleX(scale);
page.setScaleY(scale);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment