Skip to content

Instantly share code, notes, and snippets.

@davebren
Last active August 29, 2015 14:06
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 davebren/cfd392f0a436421bde4f to your computer and use it in GitHub Desktop.
Save davebren/cfd392f0a436421bde4f to your computer and use it in GitHub Desktop.
Android View Collapser Utility
package com.eski.android_utils.view.animations;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.Transformation;
public class ViewCollapser {
public static void collapse(final View view, Animation.AnimationListener listener) {
final int initialHeight = view.getMeasuredHeight();
Animation anim = new Animation() {
@Override protected void applyTransformation(float interpolatedTime, Transformation t) {
if(interpolatedTime == 1){
view.setVisibility(View.GONE);
view.getLayoutParams().height = initialHeight;
view.getParent().requestLayout();
} else {
view.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime);
view.requestLayout();
}
}
@Override public boolean willChangeBounds() { return true; }
};
anim.setAnimationListener(listener);
anim.setDuration(600);
anim.setInterpolator(new AccelerateInterpolator(5f));
view.startAnimation(anim);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment