Last active
March 14, 2019 07:31
-
-
Save laaptu/6591283 to your computer and use it in GitHub Desktop.
Android collapse animation by ValueAnimator
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
private void valueAnimateAndDelete(final View view, | |
final int deletePosition) { | |
final ViewGroup.LayoutParams lp = view.getLayoutParams(); | |
final int originalHeight = view.getHeight(); | |
ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 0); | |
animator.addListener(new AnimatorListener() { | |
@Override | |
public void onAnimationStart(Animator arg0) { | |
} | |
@Override | |
public void onAnimationRepeat(Animator arg0) { | |
} | |
@Override | |
public void onAnimationEnd(Animator arg0) { | |
lp.height = 0; | |
view.setLayoutParams(lp); | |
view.setVisibility(View.GONE); | |
} | |
@SuppressLint("NewApi") | |
@Override | |
public void onAnimationCancel(Animator arg0) { | |
} | |
}); | |
animator.addUpdateListener(new AnimatorUpdateListener() { | |
@SuppressLint("NewApi") | |
@Override | |
public void onAnimationUpdate(ValueAnimator valueAnimator) { | |
lp.height = (Integer) valueAnimator.getAnimatedValue(); | |
Log.i("view height", String.valueOf(lp.height)); | |
view.setLayoutParams(lp); | |
} | |
}); | |
animator.start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this.