Created
December 2, 2014 23:30
-
-
Save monossido/242ec653e7e41cac7665 to your computer and use it in GitHub Desktop.
Animate a view by scaling in it. Such dialer in Lollipop.Requires API level 21. Credit AOSP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * Scales in the view from scale of 0 to actual dimensions. | |
* * @param view The view to scale. | |
* * @param durationMs The duration of the scaling in milliseconds. | |
* * @param startDelayMs The delay to applying the scaling in milliseconds. | |
*/ | |
public static void scaleIn(final View view, int durationMs, int startDelayMs) { | |
AnimatorListenerAdapter listener = (new AnimatorListenerAdapter() { | |
@Override | |
public void onAnimationStart(Animator animation) { | |
view.setVisibility(View.VISIBLE); | |
} | |
@Override | |
public void onAnimationCancel(Animator animation) { | |
view.setScaleX(1); | |
view.setScaleY(1); | |
} | |
}); | |
scaleInternal(view, 0 /* startScaleValue */, 1 /* endScaleValue */, durationMs, | |
startDelayMs, listener, new PathInterpolator(0.0f, 0.0f, 0.2f, 1.0f)); | |
} | |
private static void scaleInternal(final View view, int startScaleValue, int endScaleValue, | |
int durationMs, int startDelay, AnimatorListenerAdapter listener, | |
Interpolator interpolator) { | |
view.setScaleX(startScaleValue); | |
view.setScaleY(startScaleValue); | |
final ViewPropertyAnimator animator = view.animate(); | |
animator.cancel(); | |
animator.setInterpolator(interpolator) | |
.scaleX(endScaleValue) | |
.scaleY(endScaleValue) | |
.setListener(listener) | |
.withLayer(); | |
animator.setDuration(durationMs); | |
animator.setStartDelay(startDelay); | |
animator.start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment