单一动画:
- 创建不同的animation对象
- 确定动画时间
- view开始动画
复杂动画:
1、动画集
- 创建animation set对象
- set对象加入不同的animation对象
- set对象设定时间或者不同的animation对象分别设定时间
- 开始动画
2、逐帧动画
- 创建AnimationDrawable对象
- 向对象添加资源
- 向view对象增加AnimationDrawable显示
- 开始动画
示例代码:
动画集:
<span style="font-size:14px;"> AnimationSet animation = new AnimationSet(Activity07.this,
null);
Animation a1 = new RotateAnimation(0, 360 * 3,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
Animation a2 = new ScaleAnimation(1, 0.5f, 1, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
Animation a3 = new RotateAnimation(0, -360 * 2,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
a1.setDuration(3000);
a2.setDuration(1000);
a3.setDuration(1000);
a3.setStartOffset(3000);
animation.addAnimation(a1);
animation.addAnimation(a2);
animation.addAnimation(a3);
imageView.startAnimation(animation);</span>
逐帧动画:
<span style="font-family:Microsoft YaHei;font-size:14px;"> AnimationDrawable animDrawable = new AnimationDrawable();
for (int i = 0; i < 9; i++) {
int resId = getResources().getIdentifier("img_item" + i,
"drawable", "com.tarena.tts");
animDrawable.addFrame(getResources().getDrawable(resId),
125);
}
animDrawable.setOneShot(false);
imageView.setImageDrawable(animDrawable);
animDrawable.start();</span>