补间动画,相对比较简单的动画,但可能会出现灵魂出窍的赶脚,动画移动了,但本身的事件却没有移动
首先在res/anim文件夹下写动画的各种属性
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0%"
android:toXDelta="0%"
android:fromYDelta="0%"
android:toYDelta="100%"
android:duration="6000"
android:fillAfter="true">
</translate>
然后在Java代码中调用
ImageView iv=(ImageView) findViewById(R.id.imageview);
//补间动画
Animation animation=AnimationUtils.loadAnimation(this,R.anim.spalsh_translate);
iv.setAnimation(animation);
animation.start();
帧动画
首先在drawable文件下写各种即将播放的各种图片
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/splash" android:duration="1000"/>
<item android:drawable="@drawable/splash2" android:duration="1000"/>
<item android:drawable="@drawable/splash" android:duration="1000"/>
<item android:drawable="@drawable/splash2" android:duration="1000"/>
<item android:drawable="@drawable/splash" android:duration="1000"/>
<item android:drawable="@drawable/splash2" android:duration="1000"/>
</animation-list>
然后在Java代码中调用
final AnimationDrawable anim = (AnimationDrawable) iv.getBackground();
anim.start();
属性动画
在animator文件夹下写各种属性
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:propertyName="translationX"
android:valueFrom="0"
android:valueTo="100"
android:valueType="floatType" >
</objectAnimator>
在Java代码中调用
Animator anim=AnimatorInflater.loadAnimator(this,R.animator.objectanim);
anim.setTarget(iv);
anim.start();