作用:动画合集
文件目录:res/anim/my_set.xml
<?xml version="1.0" encoding="utf-8"?><scale
android:duration="2000"
android:fromXScale="0.0"
android:fromYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="5"
android:toXScale="1.4"
android:toYScale="1.4" />
<rotate
android:duration="1000"
android:fromDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:toDegrees="360" />
<translate
android:fromXDelta="0"
android:toXDelta="-80"
android:fromYDelta="0"
android:toYDelta="-80"
android:duration="2000"
android:fillBefore="true"/>
Java代码:
AnimationSet set = (AnimationSet ) AnimationUtils.loadAnimation(this,R.anim.my_set);
imageView.startAnimation(set);
纯代码使用:(AnimationSet)
RotateAnimation rotateAnimation = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setFillAfter(true);// 设置保持动画最后的状态
rotateAnimation.setDuration(3000);// 设置动画时间
rotateAnimation.setRepeatCount(-1);//设置重复次数
imageView.startAnimation(rotateAnimation);
TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, 0, 800);
translateAnimation.setRepeatCount(-1);//设置重复次数
imageView.startAnimation(translateAnimation);
AnimationSet animationSet = new AnimationSet(true);
animationSet.addAnimation(rotateAnimation);
animationSet.addAnimation(translateAnimation);
imageView.startAnimation(animationSet);
也可以单个写,方法设置都一样。