部分缺少一下<号
1:透明
xml:<
alpha xmlns:android=“http://schemas.android.com/apk/res/android”
android:duration=“4000”
android:fromAlpha=“1.0”
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toAlpha=“0.0”
android:repeatCount=“2”
/>
activity:
Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha);
t1.startAnimation(animation);
2:旋转
xml:
rotate xmlns:android=“http://schemas.android.com/apk/res/android”
android:duration = “4000”
android:fromDegrees=“0”
android:pivotX=“50%”
android:pivotY=“50%”
android:repeatCount = “-1”
android:repeatMode = “restart”
android:toDegrees=“720”
>
activity: Animation animation1 = AnimationUtils.loadAnimation(this, R.anim.rotate);
t1.startAnimation(animation1);
3:缩放
xml:scale xmlns:android=“http://schemas.android.com/apk/res/android”
android:duration = “2000”
android:fromDegrees=“0”
android:pivotX=“50%”
android:pivotY=“50%”
android:fromXScale=“0.0”
android:fromYScale=“0.0”
android:toXScale=“2.0”
android:toYScale=“2.0”
>
4:位移:
xml:translate xmlns:android=“http://schemas.android.com/apk/res/android”
android:duration = “2000”
android:fromXDelta=“0”
android:toXDelta=“200”
android:toYDelta=“100”
android:fromYDelta=“0”>
5:以上四种组成在一块
xml:
set xmlns:android=“http://schemas.android.com/apk/res/android”>
alpha xmlns:android=“http://schemas.android.com/apk/res/android”
android:duration=“4000”
android:fromAlpha=“1.0”
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toAlpha=“0.0”
android:repeatCount=“2”
/>
<rotate xmlns:android=“http://schemas.android.com/apk/res/android”
android:duration = “4000”
android:fromDegrees=“0”
android:pivotX=“50%”
android:pivotY=“50%”
android:repeatCount = “-1”
android:repeatMode = “restart”
android:toDegrees="720"
>
</rotate>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration = "2000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:fromXScale="0.0"
android:fromYScale="0.0"
android:toXScale="2.0"
android:toYScale="2.0"
>
</scale>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration = "2000"
android:fromXDelta="0"
android:toXDelta="200"
android:toYDelta="100"
android:fromYDelta="0">
</translate>
activity:Animation animation4 = AnimationUtils.loadAnimation(this, R.anim.group); t1.startAnimation(animation4);
6:java代码实现动画效果:
RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setDuration(2000);
rotateAnimation.setRepeatCount(2);
rotateAnimation.setRepeatMode(Animation.REVERSE);
t1.startAnimation(rotateAnimation);
7:帧动画: 可以前往这个网址进行 分割gif https://www.qtool.net/gif?tdsourcetag=s_pcqq_aiomsg
在drawable下写入资源文件
注意要用animation-list
animation-list xmlns:android=“http://schemas.android.com/apk/res/android”>
item android:drawable="@mipmap/a1" android:duration=“100”>
/animation-list>
activity:
img.setBackgroundResource(R.drawable.move);
if (drawable == null) {
drawable = (AnimationDrawable) img.getBackground();
}
if (!b) {
drawable.start();
drawable.setOneShot(false);
b = true;
} else {
drawable.stop();
b = false;
}
break;
8:属性动画
ObjectAnimator rotation = ObjectAnimator.ofFloat(img, “rotation”, 0, 365, 0, 180, 0, 90, 0);
rotation.setDuration(2000);
rotation.setInterpolator(new DecelerateInterpolator());
rotation.start();