Created
December 15, 2017 11:47
-
-
Save murdly/2306f14686bf495f8029dd2c3f518f83 to your computer and use it in GitHub Desktop.
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
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