透明效果
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromAlpha="0"
android:toAlpha="1">
</alpha>
旋转效果
<rotate android:fromDegrees="0"
android:toDegrees="360"
android:duration = "1000"
android:pivotX="50%"
android:pivotY="50%"
xmlns:android="http://schemas.android.com/apk/res/android">
</rotate>
移动效果
<translate android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="10"
android:toYDelta="20"
android:duration="100"
xmlns:android="http://schemas.android.com/apk/res/android">
</translate>
缩放效果
<scale
android:fromXScale="0"
android:fromYScale="0"
android:toXScale="1"
android:toYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:duration="3000"
xmlns:android="http://schemas.android.com/apk/res/android">
</scale>
混合动画
<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>
使用动画XML
@Override
public void onClick(View v) {
Animation a = AnimationUtils.loadAnimation(MainActivity.this,R.anim.aa);
a.setAnimationListener(new Animation.AnimationListener() { //如果动画在进行中无需操作,则动画的侦听事件可以省略
@Override
public void onAnimationStart(Animation animation) {
Toast.makeText(MainActivity.this,"动画开始",Toast.LENGTH_SHORT).show();
}
@Override
public void onAnimationEnd(Animation animation) {
Toast.makeText(MainActivity.this,"动画结束",Toast.LENGTH_SHORT).show();
}
@Override
public void onAnimationRepeat(Animation animation) {
Toast.makeText(MainActivity.this,"动画重复",Toast.LENGTH_SHORT).show();
}
});
v.startAnimation(a);
}