1.Alpha 淡入淡出效果
2.Scale 缩放效果
3.Rotate 旋转效果
4.Translate 移动效果
使用步骤:
- 创建AnimationSet对象;_
- 根据需求建立相应Animation 对象;_
- 根据动画需求,为Animation对象设置相应数据;_
- 将Animation对象添加到AnimationSet对象中;_
- 使用控件对象开始执行AnimationSet;_
通用属性:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| 1.setDuration(long durationMills)
2.setFillAfter(boolean fillAfter)
3.setFillBefore(boolean fillBefore)
4.setStartOffSet(long startOffSet)
5.SetRepeatCount(int repeatCount)
|
1.淡入淡出动画
1 2 3 4 5 6 7 8 9 10
| AnimationSet animationSet=new AnimationSet(true);
AlphaAnimation alphaAnimation=new AlphaAnimation(1,0);
alphaAnimation.setDuration(1000);
animationSet.addAnimation(alphaAnimation); img.startAnimation(animationSet);
|
2.缩放效果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| AnimationSet animationSet=new AnimationSet(true);
ScaleAnimation scaleAnimation=new ScaleAnimation(1,0.1f, 1,0.1f, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0.5f); animationSet.addAnimation(scaleAnimation); animationSet.setDuration(1000); img.startAnimation(animationSet);
|
3.旋转效果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| AnimationSet animationSet=new AnimationSet(true);
RotateAnimation rotateAnimation=new RotateAnimation(0,360, Animation.RELATIVE_TO_PARENT,1f, Animation.RELATIVE_TO_PARENT,0f); rotateAnimation.setDuration(1000); animationSet.addAnimation(rotateAnimation); img.startAnimation(animationSet);
|
4.移动效果
1 2 3 4 5 6 7 8 9
| AnimationSet animationSet=new AnimationSet(true); TranslateAnimation translateAnimation=new TranslateAnimation( Animation.RELATIVE_TO_SELF,0f, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0f, Animation.RELATIVE_TO_SELF,1.0f); translateAnimation.setDuration(1000); animationSet.addAnimation(translateAnimation); img.startAnimation(animationSet);
|