透明度动画:
第一种方式:
AlphaAnimation aa = new AlphaAnimation(0, 1);
aa.setDuration(1000);
imageview.startAnimation(aa);
第二种方式:
imageview.startAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.aa));
aa.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0"
android:toAlpha="1"
android:duration="1000" >
</alpha>
旋转动画:
第一种方式:
RotateAnimation ra = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
// ra = new RotateAnimation(0, 360, 100, 50);
ra.setDuration(1000);
imageview.startAnimation(aa);
第二种方式:
imageview.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.ra));
ra.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:duration="1000"
android:pivotX="50%"
android:pivotY="50%" >
</rotate>
平移动画:
第一种方式:
TranslateAnimation ta = new TranslateAnimation(0, 200, 0, 200);
ta.setDuration(1000);
imageview.startAnimation(ta);
第二种方式:
imageview.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.ta));
ta.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:toXDelta="200"
android:fromYDelta="0"
android:toYDelta="200"
android:duration="1000" >
</translate>
缩放动画:
第一种方式:
ScaleAnimation sa = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
// sa = new ScaleAnimation(0, 1, 0, 1,100,50);
sa.setDuration(1000);
imageview.startAnimation(sa);
第二种方式:
imageview.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.sa));
sa.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="0"
android:toXScale="1"
android:fromYScale="0"
android:toYScale="1"
android:duration="1000"
android:pivotX="50%"
android:pivotY="50%" >
</scale>
动画效果混合:
第一种方式:
AnimationSet as= new AnimationSet(true);
as.setDuration(1000);
AlphaAnimation aa = new AlphaAnimation(0, 1);
aa.setDuration(1000);
as.addAnimation(aa);
TranslateAnimation ta = new TranslateAnimation(200, 0, 200, 0);
ta.setDuration(1000);
as.addAnimation(ta);
imageview.startAnimation(as);
第二种方式:
imageview.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.anim));
anim.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:shareInterpolator="true" >
<alpha
android:fromAlpha="0"
android:toAlpha="1" />
<translate
android:fromXDelta="200"
android:fromYDelta="200"
android:toXDelta="0"
android:toYDelta="0" />
</set>
动画效果侦听:
Animation a = AnimationUtils.loadAnimation(MainActivity.this, R.anim.anim);
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
Toast.makeText(MainActivity.this, "Animation end", Toast.LENGTH_SHORT).show();
}
});
imageview.startAnimation(a);