Skip to content

Instantly share code, notes, and snippets.

@laaptu
Created September 17, 2013 07:56
Show Gist options
  • Select an option

  • Save laaptu/6591295 to your computer and use it in GitHub Desktop.

Select an option

Save laaptu/6591295 to your computer and use it in GitHub Desktop.
Android Collapse Animation by decreasing height
private void animateAndDelete(final View view, final int deletePosition) {
final int height = view.getMeasuredHeight();
Animation animation = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime,
Transformation t) {
view.getLayoutParams().height = height
- (int) (height * interpolatedTime);
view.requestLayout();
}
@Override
public boolean willChangeBounds() {
return true;
}
};
animation.setDuration((int) (height * view.getContext().getResources()
.getDisplayMetrics().density));
animation.setInterpolator(new SmoothInterpolator());
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation arg0) {
}
@Override
public void onAnimationRepeat(Animation arg0) {
}
@Override
public void onAnimationEnd(Animation arg0) {
view.setVisibility(View.GONE);
}
});
view.startAnimation(animation);
}
public class SmoothInterpolator extends LinearInterpolator {
@Override
public float getInterpolation(float input) {
return (float) Math.pow(input - 1, 5) + 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment