小白mark一下碰到过的实现android动画的几种方式。
从本质上说,任何动画的实现都是一系列静态画面的连续展示。
一、使用animation
1、补间动画:通过对场景里的对象不断做图像变换(平移、缩放、旋转)产生动画效果,即是一种渐变动画;
方法1:在res/anim/文件夹下可以创建动画XML;在Activity中可以用AnimationUtils.loadAnimation来加载动画XML:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fillAfter="true"
android:fromDegrees="0"
android:pivotX="50%p"
android:pivotY="50%p"
android:toDegrees="1170" >
</rotate>
</pre><pre name="code" class="html" style="font-size: 14px;">
Animation anim = AnimationUtils.loadAnimation(this, R.anim.set);
btnTest.startAnimation(anim);
方法2: 使用Animation的实现类,可以实现同样的效果:
Animation anim=new RotateAnimation
(0, 1170, Animation.RELATIVE_TO_PARENT, 0.5f,
Animation.RELATIVE_TO_PARENT, 0.5f);
btnTest.startAnimation(anim);
Animation的子类:
RotateAnimation:旋转动画
ScaleAnimation:缩放动画
AlphaAnimation:渐变动画
TranslateAnimation:平移动画
帧动画:顺序播放事先做好的图像,是一种画面转换动画。
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/ic_launcher" android:duration="2000" />
<item android:drawable="@drawable/olivecard_a1" android:duration="2000" />
<item android:drawable="@drawable/a2" android:duration="2000" />
</animation-list>
tv.setBackgroundResource(R.drawable.frameanim);
animationDrawable=(AnimationDrawable)tv.getBackground();
animationDrawable.start();
后来接触到自定义Animation,详见我的另一篇blog:
http://blog.csdn.net/annieliu502/article/details/38731887
再后来接触到了 Android3.0以后的Animator;主要是运用ObjectAnimator和AnimatorSet来进行操作;有两篇很好的文章介绍:
android animator http://blog.csdn.net/jiabailong/article/details/14168707
Android动画机制全解析 http://blog.csdn.net/eclipsexys/article/details/38401641