Skip to content

Instantly share code, notes, and snippets.

@murdly
Created December 15, 2017 11:47
Show Gist options
  • Save murdly/2306f14686bf495f8029dd2c3f518f83 to your computer and use it in GitHub Desktop.
Save murdly/2306f14686bf495f8029dd2c3f518f83 to your computer and use it in GitHub Desktop.
public class ViewAnimationUtils {
public static AnimatorSet createLinearReveal(final View viewToReveal, final int offsetWidth, final int offsetHeight, final int duration) {
viewToReveal.clearAnimation();
final int targetWidth = viewToReveal.getMeasuredWidth();
final int targetHeight = viewToReveal.getMeasuredHeight();
viewToReveal.getLayoutParams().height = offsetHeight;
viewToReveal.requestLayout();
final ValueAnimator heightAnimator = ValueAnimator
.ofInt(offsetHeight, targetHeight)
.setDuration(duration);
heightAnimator.addUpdateListener(animation -> {
viewToReveal.getLayoutParams().height = (int) animation.getAnimatedValue();
viewToReveal.requestLayout();
});
final ValueAnimator widthAnimator = ValueAnimator
.ofInt(offsetWidth, targetWidth)
.setDuration(duration);
widthAnimator.addUpdateListener(animation -> {
viewToReveal.getLayoutParams().width = (int) animation.getAnimatedValue();
viewToReveal.requestLayout();
});
final AnimatorSet set = new AnimatorSet();
set.playSequentially(widthAnimator, heightAnimator);
set.setInterpolator(new AccelerateInterpolator());
return set;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment