Created
June 23, 2015 17:01
-
-
Save flasher297/b937dbe36ceddafd872c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* This animation supports API >= 10 | |
*/ | |
public class CollapseAnimation extends Animation | |
{ | |
// -- Construction | |
/** | |
* | |
* @param view The view to be animated | |
* @param startingHeight | |
* @param endingHeight | |
* @param down True = expanding, false = collapsing | |
*/ | |
public CollapseAnimation(View view, int startingHeight, int endingHeight, boolean down, long duration) | |
{ | |
this.mView = view; | |
this.mStartingHeight = startingHeight; | |
this.mEndingHeight = endingHeight; | |
this.mDown = down; | |
setDuration(duration); | |
} | |
// -- Functions | |
@Override | |
protected void applyTransformation(float interpolatedTime, Transformation t) | |
{ | |
int newHeight; | |
if (mDown) { | |
newHeight = (int) (((mEndingHeight - mStartingHeight) * interpolatedTime) + mStartingHeight); | |
} | |
else { | |
newHeight = (int) (((mEndingHeight - mStartingHeight)* (1 - interpolatedTime)) + mStartingHeight); | |
} | |
mView.getLayoutParams().height = newHeight; | |
mView.requestLayout(); | |
} | |
@Override | |
public void initialize(int width, int height, int parentWidth, int parentHeight) { | |
super.initialize(width, height, parentWidth, parentHeight); | |
} | |
@Override | |
public boolean willChangeBounds() { | |
return true; | |
} | |
// -- Constants | |
// newHeight = x * 0.25; oldHeight = newHeight * 4; | |
public static final float COLLAPSE_HEIGHT_MULTIPLIER = 0.25f; | |
public static final float EXPAND_HEIGHT_MULTIPLIER = 4f; | |
public static final long DEFAULT_DURATION = 500; | |
// -- Variables | |
private final View mView; | |
private final boolean mDown; | |
private final int mEndingHeight; | |
private final int mStartingHeight; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment