一种是tweened animation(渐变动画) XML中 JavaCode alpha AlphaAnimation scale ScaleAnimation |
一种是frame by frame(画面转换动画) XML中 JavaCode translate TranslateAnimation rotate RotateAnimation |
两种实现方法
1 java 代码
-
//
TODO Auto-generated method stub -
//第一个参数fromX为动画起始时
X坐标上的伸缩尺寸 -
//第二个参数toX为动画结束时
X坐标上的伸缩尺寸 - //第三个参数fromY为动画起始时Y坐标上的伸缩尺寸
- //第四个参数toY为动画结束时Y坐标上的伸缩尺寸
- /*
-
* 说明: 以上四种属性值 0.0表示收缩到没有 1.0表示正常无伸缩 值小于1.0表示收缩 值大于1.0表示放大 -
*/ - //第五个参数pivotXType为动画在X轴相对于物件位置类型
- //第六个参数pivotXValue为动画相对于物件的X坐标的开始位置
- //第七个参数pivotXType为动画在Y轴相对于物件位置类型
- //第八个参数pivotYValue为动画相对于物件的Y坐标的开始位置
-
ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 0.5f,
1f, 0.5f, - Animation.RELATIVE_TO_SELF, 0.5f,
- Animation.RELATIVE_TO_SELF, 0.5f);
- scaleAnimation.setDuration(2000);
- findViewById(R.id.img).setAnimation(scaleAnimation);
-
//
TODO Auto-generated method stub - //第一个参数fromDegrees为动画起始时的旋转角度
- //第二个参数toDegrees为动画旋转到的角度
- //第三个参数pivotXType为动画在X轴相对于物件位置类型
- //第四个参数pivotXValue为动画相对于物件的X坐标的开始位置
- //第五个参数pivotXType为动画在Y轴相对于物件位置类型
- //第六个参数pivotYValue为动画相对于物件的Y坐标的开始位置
- RotateAnimation rotateAnimation = new RotateAnimation(0, 180,
- Animation.RELATIVE_TO_SELF, 0.5f,
- Animation.RELATIVE_TO_SELF, 2.0f);
- rotateAnimation.setDuration(2000);
- findViewById(R.id.img).setAnimation(rotateAnimation);
-
//
TODO Auto-generated method stub -
//fromXDelta为动画起始时
X坐标上的移动位置 -
//toXDelta为动画结束时
X坐标上的移动位置 - //fromYDelta为动画起始时Y坐标上的移动位置
- //toYDelta为动画结束时Y坐标上的移动位置
-
//Animation.RELATIVE_TO_SELF
相对本控件 -
TranslateAnimation translateAnimation
= new TranslateAnimation( - Animation.RELATIVE_TO_SELF, 1.0f,
- Animation.RELATIVE_TO_SELF, 1.0f,
- Animation.RELATIVE_TO_SELF, 1.0f,
- Animation.RELATIVE_TO_SELF, 1.0f);
- //设置动画持续时间
- translateAnimation.setDuration(2000);
- findViewById(R.id.img).setAnimation(translateAnimation);
-
//
第一个参数fromAlpha为 动画开始时候透明度 -
//
第二个参数toAlpha为 动画结束时候透明度 -
//
0.0表示完全透明