Last active
December 21, 2015 12:19
-
-
Save liu7yong/6304579 to your computer and use it in GitHub Desktop.
An android animation that collapse or expand a View object.
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 us.liuyong.widget; | |
import android.view.View; | |
import android.view.ViewGroup.LayoutParams; | |
import android.view.animation.Animation; | |
import android.view.animation.Transformation; | |
/** | |
* @author liuyong | |
* | |
*/ | |
public class DropDownAnimation extends Animation { | |
public static final int DOWN = 0; | |
public static final int UP = 1; | |
private int mMaxHeight; | |
private View mView; | |
private int mDirection; | |
public DropDownAnimation(View view, int maxHeight, int direction) { | |
mView = view; | |
mMaxHeight = maxHeight; | |
mDirection = direction; | |
} | |
@Override | |
protected void applyTransformation(float interpolatedTime, Transformation t) { | |
int newHeight; | |
if (mDirection == DOWN) { | |
newHeight = (int) (mMaxHeight * interpolatedTime); | |
} else { | |
newHeight = (int) (mMaxHeight * (1.0f - interpolatedTime)); | |
} | |
LayoutParams params = mView.getLayoutParams(); | |
params.height = newHeight; | |
mView.setLayoutParams(params); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The usage is very simple: