动画之基础动画(view动画)

**

android中提供了4中动画:

**

AlphaAnimation 透明度动画效果
ScaleAnimation 缩放动画效果
TranslateAnimation 位移动画效果
RotateAnimation 旋转动画效果



一、ScaleAnimation 动画

**float fromX 动画起始时 X坐标上的伸缩尺寸
float toX 动画结束时 X坐标上的伸缩尺寸
float fromY 动画起始时Y坐标上的伸缩尺寸
float toY 动画结束时Y坐标上的伸缩尺寸
int pivotXType 动画在X轴相对于物件位置类型
float pivotXValue 动画相对于物件的X坐标的开始位置
int pivotYType 动画在Y轴相对于物件位置类型
float pivotYValue 动画相对于物件的Y坐标的开始位置**

** 设置缩放动画 */ 
final ScaleAnimation animation =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f, 
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
animation.setDuration(2000);//设置动画持续时间 
/** 常用方法 */ 
//animation.setRepeatCount(int repeatCount);//设置重复次数 
//animation.setFillAfter(boolean);//动画执行完后是否停留在执行完的状态 
//animation.setStartOffset(long startOffset);//执行前的等待时间 
image.setAnimation(animation); 
/** 开始动画 */ 
animation.startNow(); 
/** 结束动画 */ 
animation.cancel(); 


二、RotateAnimation 动画

float fromDegrees:旋转的开始角度。
float toDegrees:旋转的结束角度。
int pivotXType:X轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float pivotXValue:X坐标的伸缩值。
int pivotYType:Y轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float pivotYValue:Y坐标的伸缩值。

/** 设置旋转动画 */ 
final RotateAnimation animation =new RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF, 
0.5f,Animation.RELATIVE_TO_SELF,0.5f); 
animation.setDuration(3000);//设置动画持续时间 
/** 常用方法 */ 
//animation.setRepeatCount(int repeatCount);//设置重复次数 
//animation.setFillAfter(boolean);//动画执行完后是否停留在执行完的状态 
//animation.setStartOffset(long startOffset);//执行前的等待时间 
image.setAnimation(animation); 
/** 开始动画 */ 
animation.startNow(); 
/** 结束动画 */ 
animation.cancel(); 

猜你喜欢

转载自blog.csdn.net/qq_22230935/article/details/58606928