使用xml定义补间动画

来源:互联网 发布:网络打印提示被挂起 编辑:程序博客网 时间:2024/04/20 20:44

rotate.xml:

旋转:

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <rotate        android:repeatMode="reverse"        android:repeatCount="1"
//起始角度        android:fromDegrees="0"        android:toDegrees="360"        android:pivotX="50%"        android:pivotY="50%"        ></rotate></set>
//加载xml文件
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate);iv.setAnimation(animation);
缩放:
scale.xml:
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <scale        android:duration="2000"
//动画执行模式        android:repeatMode="reverse"
//动画重复次数        android:repeatCount="1"
        android:fromXScale="1.0"        android:toXScale="0.5"        android:fromYScale="1.0"        android:toYScale="0.5"
//相对于自身        android:pivotX="50%"        android:pivotY="50%"        ></scale></set>
Animation scaleAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.scale);iv.setAnimation(scaleAnimation);
位移:
translate.xml:
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <translate        android:duration="2000"
//设置动画结束之后,动画停留在结束位置        android:fillAfter="true"        android:repeatCount="1"        android:repeatMode="reverse"
//x轴不动        android:fromXDelta="0%p"        android:toXDelta="0%p"
//y轴移动父节点的20%的距离        android:fromYDelta="0%p"        android:toYDelta="20%p"        ></translate></set>
Animation translateAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.translate);iv.setAnimation(translateAnimation);


0 0