`
scliu0718
  • 浏览: 51638 次
  • 性别: Icon_minigender_1
  • 来自: 成都
文章分类
社区版块
存档分类
最新评论

Android之自定义Animation

 
阅读更多

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);
}

}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics