Android中的动画主要分为三类
1.Drawable Animation
2.View Animation
3.Property Animation
这里介绍其中的两类,Drawable Animation(逐帧动画)和View Animation
Drawable Animation 逐帧播放每一张图片,就好像动画播放一样。
View Animation 包括 平移动画 translate 、缩放动画 scale 、旋转动画 rotate 、渐变动画 alpha
Drawable Animation (逐帧动画)
我们使用 animation-list 来定义动画xml文件,在工程res的anim文件夹或者drawable文件夹下建立我们的动画文件
anim_list.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<!-- onshot 为true表示只播放一次,false表示循环播放 -->
<item
android:drawable="@drawable/one"
android:duration="500"/>
<item
android:drawable="@drawable/two"
android:duration="500"/>
<item
android:drawable="@drawable/three"
android:duration="500"/>
<item
android:drawable="@drawable/four"
android:duration="500"/>
<item
android:drawable="@drawable/five"
android:duration="500"/>
<item
android:drawable="@drawable/six"
android:duration="500"/>
</animation-list>
使用AnimationDrawable 启动动画,代码如下,调用stop可以停止动画
private AnimationDrawable walkDrawable;
image.setImageResource(R.drawable.anim_list);
walkDrawable = (AnimationDrawable)image.getDrawable();
walkDrawable.start();
View Animation
在代码中定义动画这里不做介绍,主要介绍在xml中定义动画
渐变动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<alpha
android:duration=