Skip to content

Instantly share code, notes, and snippets.

@yccheok
Created January 24, 2024 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yccheok/02b215b6243bfb1d58dc531d89aea9e8 to your computer and use it in GitHub Desktop.
Save yccheok/02b215b6243bfb1d58dc531d89aea9e8 to your computer and use it in GitHub Desktop.
public static void expandAnimation(View view) {
int config_shortAnimTime = WeNoteApplication.instance().getResources().getInteger(android.R.integer.config_shortAnimTime);
int prevHeight = view.getHeight();
// TODO:
int targetHeight = dpToPixel(120);
ValueAnimator valueAnimator = ValueAnimator.ofInt(prevHeight, targetHeight);
valueAnimator.setInterpolator(new AccelerateInterpolator());
valueAnimator.setDuration(config_shortAnimTime);
valueAnimator.addUpdateListener(animation -> {
view.getLayoutParams().height = (int) animation.getAnimatedValue();
view.requestLayout();
});
valueAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation)
{
view.getLayoutParams().height = targetHeight;
view.requestLayout();
}
});
view.setVisibility(View.VISIBLE);
valueAnimator.start();
}
public static void collapseAnimation(View view) {
int config_shortAnimTime = WeNoteApplication.instance().getResources().getInteger(android.R.integer.config_shortAnimTime);
int prevHeight = view.getHeight();
int targetHeight = 0;
ValueAnimator valueAnimator = ValueAnimator.ofInt(prevHeight, targetHeight);
valueAnimator.setInterpolator(new AccelerateInterpolator());
valueAnimator.setDuration(config_shortAnimTime);
valueAnimator.addUpdateListener(animation -> {
view.getLayoutParams().height = (int) animation.getAnimatedValue();
view.requestLayout();
});
valueAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation)
{
view.setVisibility(View.GONE);
}
});
valueAnimator.start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment