转自:http://www.cnblogs.com/lee0oo0/archive/2012/05/22/2513008.html
一、Animations一般分为两大类,一类是补间动画(Tweened):如淡入淡出,旋转,缩放,移动;另一类是帧动画Frame-by-Frame,就如电影一般由多张图片按照一定的时间间隔显示。
二、Tweened Animations的使用(两种方式 )
第一种:
1. 创建一个AnimationSet对象,AnimationSet animationSet = new AnimationSet (boolean b); //b为true表示共享Interpolator
2. 根据需要创建相应的Animation对象(AlphaAnimation、RotateAnimation、ScaleAnimation、TranslateAnimation)
3. 根据软件动画的需求,为Animation对象设置相应的数据
4. 将Animation对象添加到AnimationSet对象当中,使用addAnimation方法
5. 使用控件对象开始执行AnimationSet
注意:alpha取值 0-1.0,表示的意思为不透明度,0是全透明状态,1是完全不透明状态
第二种:
1. 在res文件夹下面新建一个名为anim的文件夹.
2. 创建xml文件,并首先加入set标签,标签如下:
<set xmlns:android="http://schemas.android.com/apk/res/android">
</set>
3. 在set标签中加入rotate,alpha,scale或者translate标签,例子如下:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="3000"
android:fromAlpha="0.1"
android:toAlpha="1.0" />
<rotate
android:duration="3000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="+350" />
</set>
1)android:pivotX="50"这种方法使用绝对位置定位
3)android:pivotX="50%p"这种方法相对于控件的父控件定位
4. 在代码当中使用AnimationUtils当中装载xml文件,并生成Animation对象,AnimationUtils.loadAnimation
三、Frame-By-Frame(帧动画)使用方法
1. 在res/drawable当中创建一个xml文件(animation_list.xml)
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item
android:drawable="drawable/nv1"
android:duration="500" />
<item
android:drawable="drawable/nv2"
android:duration="500" />
<item
android:drawable="drawable/nv3"
android:duration="500" />
<item
android:drawable="drawable/nv4"
android:duration="500" />
</animation-list>
2.
imageView. setBackgroundResource(R.drawable.animation_list);
3.
AnimationDrawable animationDrawable = (AnimationDrawable)imageView.getBackground();
4.
animationDrawable.start();