// TODO Auto-generated method stub
if (v == alphaBtn) {
// 透明动画的类
AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0.1f);
// 设置动画持续时间
alphaAnimation.setDuration(3000);
// 保持动画后的状态
alphaAnimation.setFillAfter(true);
// 重复的次数
alphaAnimation.setRepeatCount(-1);
// 重复的类型 RESTART - 每次从头开始播放动画 REVERSE - 反向播放动画
alphaAnimation.setRepeatMode(AlphaAnimation.REVERSE);
// 让图片组件开始加载动画
imageView.startAnimation(alphaAnimation);
}
if (v == scaleBtn) {
// 缩放动画的类。从图片的中心位置开始缩放
ScaleAnimation scaleAnimation = new ScaleAnimation(1, 0.1f, 1,
0.1f, Animation.RELATIVE_TO_SELF, 0.1f,
Animation.RELATIVE_TO_SELF, 0.1f);
// 设置动画持续时间
scaleAnimation.setDuration(3000);
// 保持动画后的状态
scaleAnimation.setFillAfter(true);
// 重复的次数
scaleAnimation.setRepeatCount(-1);
// 重复的类型 RESTART - 每次从头开始播放动画 REVERSE - 反向播放动画
scaleAnimation.setRepeatMode(AlphaAnimation.REVERSE);
// 让图片组件开始加载动画
imageView.startAnimation(scaleAnimation);
}
if (v == translateBtn) {
//移动动画
TranslateAnimation translateAnimation = new TranslateAnimation(0,150, 0, 150);
// 设置动画持续时间
translateAnimation.setDuration(3000);
// 保持动画后的状态
translateAnimation.setFillAfter(true);
// 重复的次数
translateAnimation.setRepeatCount(-1);
// 重复的类型 RESTART - 每次从头开始播放动画 REVERSE - 反向播放动画
translateAnimation.setRepeatMode(AlphaAnimation.REVERSE);
// 让图片组件开始加载动画
imageView.startAnimation(translateAnimation);
}
if (v == rotateBtn) {
//旋转动画
Animation.RELATIVE_TO_SELF, 0.8f,
Animation.RELATIVE_TO_SELF, 0.8f);
// 设置动画持续时间
rotateAnimation.setDuration(3000);
// 保持动画后的状态
rotateAnimation.setFillAfter(true);
// 重复的次数
rotateAnimation.setRepeatCount(-1);
// 重复的类型 RESTART - 每次从头开始播放动画 REVERSE - 反向播放动画
rotateAnimation.setRepeatMode(AlphaAnimation.RESTART);
// 让图片组件开始加载动画
imageView.startAnimation(rotateAnimation);
}
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<alpha
android:duration="2000" android:fillAfter="true" android:fromAlpha="1" android:toAlpha="0.5"/>
<scale android:duration="2000" android:fromXScale="1"android:fromYScale="1"
android:pivotX="50%" android:pivotY="50%" android:toXScale="0.5" android:toYScale="0.5" >
</scale>
<translate android:duration="2000" android:fromXDelta="300" android:fromYDelta="300"
android:toXDelta="0" android:toYDelta="0" />
<rotate android:duration="2000" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%"
android:repeatCount="0" android:repeatMode="reverse" android:toDegrees="360"/>
</set>