1.xml写法
alpha_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromAlpha="1.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toAlpha="0.0" />
rotate_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromDegrees="0"
android:pivotX="50%p"
android:pivotY="50%p"
android:toDegrees="360" />
scale_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="0.0"
android:fromYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.0"
android:toYScale="1.0" />
translate_anim.xml
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="100"
android:toYDelta="100"
/>
set_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="1000"
android:fromAlpha="1.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toAlpha="0.0" />
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromDegrees="0"
android:pivotX="50%p"
android:pivotY="50%p"
android:toDegrees="360" />
</set>
使用
public void onAlpha(View view) {
Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha_anim);
animation.setFillBefore(true);
mImageView.startAnimation(animation);
}
2.代码实现
alpha_anim
AlphaAnimation alpha = new AlphaAnimation(0.0f, 1.0f);
alpha.setDuration(1000);
alpha.setFillBefore(true);
alpha.setInterpolator(new LinearInterpolator());
mImageView.setAnimation(alpha);
alpha.start();
rotate_anim
RotateAnimation rotateAnimation=new RotateAnimation(0f,360f,50f,50f);
scale_anim
ScaleAnimation scaleAnimation=new ScaleAnimation(0,50,0,50);
translate_anim
TranslateAnimation translate=new TranslateAnimation(0f,100f,0,100f);
set_anim
AnimationSet animationSet=new AnimationSet(true);
animationSet.addAnimation(translate);
animationSet.addAnimation(rotateAnimation);
animationSet.addAnimation(scaleAnimation);