Skip to content

Instantly share code, notes, and snippets.

@oianmol
Created November 12, 2015 11:41
Show Gist options
  • Save oianmol/242fa326fd5f4fb30c9c to your computer and use it in GitHub Desktop.
Save oianmol/242fa326fd5f4fb30c9c to your computer and use it in GitHub Desktop.
public class CircularViewModifier extends ViewModifier {
private static final int CIRCLE_OFFSET = 500;
private static final float DEGTORAD = 1.0f / 180.0f * (float) Math.PI;
private static final float SCALING_RATIO = 0.001f;
private static final float TRANSLATION_RATIO = 0.09f;
@Override
void applyToView(final View v, final RecyclerView parent) {
final float halfHeight = v.getHeight() * 0.5f;
final float parentHalfHeight = parent.getHeight() * 0.5f;
final float y = v.getY();
final float rot = parentHalfHeight - halfHeight - y;
v.setPivotX(0.0f);
v.setPivotY(halfHeight);
v.setRotation(rot * 0.05f);
v.setTranslationX((float) ((-Math.cos(rot * TRANSLATION_RATIO * DEGTORAD) + 1) * CIRCLE_OFFSET));
final float scale = 1.0f - Math.abs(parentHalfHeight - halfHeight - y) * SCALING_RATIO;
v.setScaleX(scale);
v.setScaleY(scale);
}
public abstract class ViewModifier {
abstract void applyToView(View v, RecyclerView parent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment