Last active
August 29, 2015 14:06
-
-
Save davebren/cfd392f0a436421bde4f to your computer and use it in GitHub Desktop.
Android View Collapser Utility
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
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