1.什么是动画
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromXScale="0.0"
android:fromYScale="0.0"
android:pivotX=“1"
android:pivotY=“0.5“
android:toXScale="1.0"
android:toYScale="1.0"
android:fillAfter="true"/>
数值(默认以px为单位) 100
百分数,如:50%(以当前视图的宽度或高度其为基数来计算)
百分数+p,如:50%p(以父视图的宽度或高度其为基数来计算)
4.旋转动画(RotateAnimation)
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="5000"
android:fromDegrees="+90“
android:toDegrees="-90"
android:pivotX="0%"
android:pivotY="0%"/>
5.透明度动画(AlphaAnimation)
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:startOffset="500"
android:duration="1000" />
6.平移动画(TranslateAnimation)
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromXDelta="-100%p"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
7.复合动画(Code AnimationSet)
// 复合动画对象
AnimationSet animationSet = new AnimationSet(false);
// 添加一个单一动画
animationSet.addAnimation(alpha);
animationSet.addAnimation(rotate);
//开启动画
iv_animation.startAnimation(animationSet);
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="2000"
android:fromAlpha="0.0"
android:toAlpha="1.0"/>
<rotate
android:duration="1000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%“
android:toDegrees="360"/>
</set>
8.Interpolator属性的使用
Interpolator被用来修饰动画效果,定义动画的变化率,可以使存在的动画效果accelerated(加速),decelerated(减速),repeated(重复)等。
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<itemandroid:drawable="@drawable/nv1"android:duration="500" />
<itemandroid:drawable="@drawable/nv2"android:duration="500"/>
<itemandroid:drawable="@drawable/nv3"android:duration="500" />
<itemandroid:drawable="@drawable/nv4"android:duration="500" />
</animation-list>
<ImageView
android:id="@+id/iv_dv"
android:layout_width=“80dp"
android:layout_height=“80dp"
android:layout_marginTop="160dp"
android:background="@drawable/anim_da"/>
11.启动Drawable动画
//得到背景动画图上
AnimationDrawable ad =null;
ad = (AnimationDrawable) imageView.getBackground();
//启动动画
ad.start();
//停止动画
ad.stop();