public class AnimTest extends Activity{
// ....生命周期方法略
public void startAnim(View view, int deltaY){MyAnim anim = new MyAnim(view,deltaY,true);
anim .setFillAfter(true);
anim.setFillEnabled(true);
anim.setDuration(500);
anim.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
button1.setEnabled(false);
button2.setEnabled(true);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
button1.setVisibility(View.INVISIBLE);
button2.setVisibility(View.VISIBLE);
}
});
view.startAnimation(anim);
}
class MyAnim extends Animation {
private View view;
private int deltaY;
private boolean initiallyCollapsed;
public MyAnim(View view, int deltaY, boolean initiallyCollapsed) {
this.view = view;
this.deltaY = deltaY;
this.initiallyCollapsed = initiallyCollapsed;
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
int newHeight;
if (this.initiallyCollapsed) {
newHeight = (int) (this.deltaY * interpolatedTime);
} else {
newHeight = (int) (this.deltaY * (1 - interpolatedTime));
}
view.getLayoutParams().height = newHeight;
view.requestLayout();
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
}
}
}