帧动画
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true" >
<item
android:drawable="@drawable/c1"
android:duration="200"/>
</animation-list>
AnimationDrawable animationDrawable =(AnimationDrawable) imge2.getDrawable();
animationDrawable.start();
补间动画
在res目录中新建anim文件夹
在anim目录中新建一个my_anim.xml(注意文件名小写)
android:duration=”2000” 动画消耗时间
android:fillAfter=”true” 动画结束后停留在开始帧还结束帧
android:fillBefore=”false”
alph 渐变透明度动画效果
scale 渐变尺寸伸缩动画效果
translate 画面转换位置移动动画效果
rotate 画面转移旋转动画效果
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fillBefore="false">
<scale
android:pivotY="50%"
android:pivotX="50%"
android:fromXScale="1"
android:fromYScale="1"
android:toXScale="2"
android:toYScale="2"/>
</set>
//加载动画文件
Animation animation1 = AnimationUtils.loadAnimation(this,R.anim.test1);
Animation animation2 = AnimationUtils.loadAnimation(this,R.anim.test2);
animation1.getRepeatCount()
AnimationSet set=new AnimationSet(true);
set.addAnimation(animation1);
set.addAnimation(animation2);
//启动动画
imge.startAnimation(set);
属性动画:
View在3.0之后引入的几个新的属性,并设置了其getter和setter方法:
1)translationX 和 translationY:这两个属性控制了View所处的位置,它们的值是由layout容器设置的,是相对于坐标原点(0,0左上角)的一个偏移量。
2)rotation, rotationX 和 rotationY:控制View绕着轴点(pivotX和pivotY)旋转。
3)scaleX 和 scaleY:控制View基于pivotX和pivotY的缩放。
4)pivotX 和 pivotY:旋转的轴点和缩放的基准点,默认是View的中心点。
5)x 和 y:描述了view在其父容器中的最终位置,是左上角左标和偏移量(translationX,translationY)的和。
6)aplha:透明度,1是完全不透明,0是完全透明。
res/animator/tesst.xml
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:propertyName="translationX"
android:valueFrom="0dp"
android:valueTo="300dp"
/>
private ImageView imge2;
ObjectAnimator oa=(ObjectAnimator) AnimatorInflater.loadAnimator(this,R.animator.test);
oa.setTarget(imge2);
oa.start();