Last active
January 14, 2022 09:00
-
-
Save Budincsevity/5c7873f50a3972c8cbc8 to your computer and use it in GitHub Desktop.
Change the height of a layout with ValueAnimator
This file contains hidden or 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
private RelativeLayout mCalendarView; | |
. | |
. | |
. | |
private void expandLayout() { | |
final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); | |
final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); | |
mCalendarView.measure(widthSpec, heightSpec); | |
ValueAnimator animator = slideAnimator(0, 750); | |
nimator.start(); | |
} | |
private void collapseLayout() { | |
int finalHeight = mCalendarView.getHeight(); | |
ValueAnimator animator = slideAnimator(finalHeight, 0); | |
animator.start(); | |
} | |
private ValueAnimator slideAnimator(int start, int end) { | |
ValueAnimator animator = ValueAnimator.ofInt(start, end); | |
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { | |
@Override | |
public void onAnimationUpdate(ValueAnimator valueAnimator) { | |
int value = (Integer) valueAnimator.getAnimatedValue(); | |
ViewGroup.LayoutParams layoutParams = mCalendarView.getLayoutParams(); | |
layoutParams.height = value; | |
mCalendarView.setLayoutParams(layoutParams); | |
} | |
}); | |
return animator; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment