欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Android animation 示例

程序员文章站 2022-02-13 20:08:25
...

private void addAnimation(String name) {
array.add(name);
if (name.equals("alpha")) {
anim = new AlphaAnimation(0f, 1.0f);
anim.setDuration(time);
anim.setFillAfter(true);
anims.add(anim);

anim = new AlphaAnimation(1f, 0f);
anim.setDuration(time);
anim.setFillAfter(false);
exit_anims.add(anim);

} else if (name.equals("rotate")) {
anim = new RotateAnimation(0.0f, 360.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
anim.setDuration(time);
anim.setFillAfter(true);
anims.add(anim);

anim = new RotateAnimation(0.0f, -360.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
anim.setDuration(time);
anim.setFillAfter(false);
exit_anims.add(anim);
} else if (name.equals("translate")) {
anim = new TranslateAnimation(width, 0f, 0, 0);
anim.setDuration(time);
anim.setFillAfter(true);
anims.add(anim);

anim = new TranslateAnimation(0, -width, 0, 0);
anim.setDuration(time);
anim.setFillAfter(false);
exit_anims.add(anim);
} else if (name.equals("scale")) {
anim = new ScaleAnimation(0.0f, 1.0f, 1f, 1f, Animation.RELATIVE_TO_PARENT, 0.5f,
Animation.RELATIVE_TO_PARENT, 0.5f);
anim.setDuration(time);
anim.setFillAfter(true);
anim.setStartOffset(200);
anims.add(anim);

anim = new ScaleAnimation(1.0f, 0.0f, 1f, 1f, Animation.RELATIVE_TO_PARENT, 0.5f,
Animation.RELATIVE_TO_PARENT, 0.5f);
anim.setDuration(time);
anim.setFillAfter(false);
anim.setStartOffset(200);
exit_anims.add(anim);
} else {
myView1.setBackgroundResource(R.drawable.widget_animate);
frameAnimation = (AnimationDrawable) myView1.getBackground();
}
}

private void startAnimation(int pos) {
position = pos;

if (position >= 4) {
myView1.setVisibility(View.VISIBLE);
frameAnimation.start();
} else {
myView.setVisibility(View.VISIBLE);
myView.startAnimation(anims.get(pos));
}
}
相关标签: animation