Skip to content

Instantly share code, notes, and snippets.

@mikeseif
Last active December 11, 2015 07:38
Show Gist options
  • Save mikeseif/4567535 to your computer and use it in GitHub Desktop.
Save mikeseif/4567535 to your computer and use it in GitHub Desktop.
SlideTransformer for a Photo gallery pager I'm working on, it behaves similar to the paging of the stock App Launcher. Pages zoom / fade in as if they were stacked on top of each other, with the leaving page translating out to the left. @TargetApi set to Honeycomb for lint, I haven't tested on Gingerbread yet and it may need tweaking. Instantiat…
/**
* {@link android.support.v4.view.ViewPager.PageTransformer} to translate / transform 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) {
final int width = page.getWidth();
float scale = 1 - (fScaleFactor * position);
page.setAlpha(1 - position);
page.setScaleX(scale);
page.setScaleY(scale);
page.setTranslationX((width * (1 - position)) - width);
}
}
}
@talapbekov
Copy link

Seriously?!

what is wrong with the name?

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