Android动画(旋转+透明+缩放+位移+效果一起使用+帧动画+属性动画)

部分缺少一下<号
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”
>

activity: Animation animation2 = AnimationUtils.loadAnimation(this, R.anim.scale); t1.startAnimation(animation2);

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”>

activity: Animation animation3 = AnimationUtils.loadAnimation(this, R.anim.translate); t1.startAnimation(animation3);

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();

发布了25 篇原创文章 · 获赞 0 · 访问量 1616
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览