Android中的Animation动画效果
Android中的Animation动画效果可以通过两种方式实现:
在XML中实现动画效果
alpha
渐变透明度动画效果
- ?
- ?
- ?
- ?
- ?
- private?Animation?myAnimation_Alpha;? ??private?Animation?myAnimation_Scale;? ?? private?Animation?myAnimation_Translate;? ?? private?Animation?myAnimation_Rotate;? ?? ??? ??//根据各自的构造方法来初始化一个实例对象? ?? myAnimation_Alpha=new?AlphaAnimation(0.1f,?1.0f);? ?? ??myAnimation_Scale?=new?ScaleAnimation(0.0f,?1.4f,?0.0f,?1.4f,? ?? ?????????????Animation.RELATIVE_TO_SELF,?0.5f,?Animation.RELATIVE_TO_SELF,?0.5f);? ?? ??myAnimation_Translate=new?TranslateAnimation(30.0f,?-80.0f,?30.0f,?300.0f);? ?? ??myAnimation_Rotate=new?RotateAnimation(0.0f,?+350.0f,???????????????Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,?0.5f);???
Android动画解析
AlphaAnimation
① AlphaAnimation类对象定义
private AlphaAnimation myAnimation_Alpha;
② AlphaAnimation类对象构造
AlphaAnimation(float fromAlpha, float toAlpha)
//第一个参数fromAlpha为 动画开始时候透明度
//第二个参数toAlpha为 动画结束时候透明度
myAnimation_Alpha=new AlphaAnimation(0.1f, 1.0f);
//说明:
//??????????????? 0.0表示完全透明
//??????????????? 1.0表示完全不透明
③ 设置动画持续时间
myAnimation_Alpha.setDuration(5000);
//设置时间持续时间为 5000毫秒
ScaleAnimation
①ScaleAnimation类对象定义
private AlphaAnimation myAnimation_Scale;
② ScaleAnimation类对象构造
ScaleAnimation(float fromX, float toX, float fromY, float toY,
?????????? int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
//第一个参数fromX为动画起始时 X坐标上的伸缩尺寸??
//第二个参数toX为动画结束时 X坐标上的伸缩尺寸???
//第三个参数fromY为动画起始时Y坐标上的伸缩尺寸??
//第四个参数toY为动画结束时Y坐标上的伸缩尺寸
/*说明:
??????????????????? 以上四种属性值??
??????????????????? 0.0表示收缩到没有
??????????????????? 1.0表示正常无伸缩???
??????????????????? 值小于1.0表示收缩
??????????????????? 值大于1.0表示放大
*/
//第五个参数pivotXType为动画在X轴相对于物件位置类型
//第六个参数pivotXValue为动画相对于物件的X坐标的开始位置
//第七个参数pivotXType为动画在Y轴相对于物件位置类型?
//第八个参数pivotYValue为动画相对于物件的Y坐标的开始位置
myAnimation_Scale =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f,
???????????? Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
③ 设置动画持续时间
myAnimation_Scale.setDuration(700);
//设置时间持续时间为 700毫秒
TranslateAnimation
① TranslateAnimation类对象定义
private AlphaAnimation myAnimation_Translate;
② TranslateAnimation类对象构造
TranslateAnimation(float fromXDelta, float toXDelta,
?????????????????????? float fromYDelta, float toYDelta)
//第一个参数fromXDelta为动画起始时 X坐标上的移动位置??
//第二个参数toXDelta为动画结束时 X坐标上的移动位置????
//第三个参数fromYDelta为动画起始时Y坐标上的移动位置???
//第四个参数toYDelta为动画结束时Y坐标上的移动位置
③ 设置动画持续时间
myAnimation_Translate.setDuration(2000);
//设置时间持续时间为 2000毫秒
RotateAnimation
① RotateAnimation类对象定义
private AlphaAnimation myAnimation_Rotate;
② RotateAnimation类对象构造
RotateAnimation(float fromDegrees, float toDegrees,
??????????? int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
//第一个参数fromDegrees为动画起始时的旋转角度??
//第二个参数toDegrees为动画旋转到的角度?
//第三个参数pivotXType为动画在X轴相对于物件位置类型
//第四个参数pivotXValue为动画相对于物件的X坐标的开始位置
//第五个参数pivotXType为动画在Y轴相对于物件位置类型?
//第六个参数pivotYValue为动画相对于物件的Y坐标的开始位置
myAnimation_Rotate=new RotateAnimation(0.0f, +350.0f,???????????? Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF, 0.5f)
③ 设置动画持续时间
myAnimation_Rotate.setDuration(3000);
//设置时间持续时间为 3000毫秒
