1、res下创建anim文件夹,在下面创建animation-list的xml文件,
<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/firefox_animation_0"
android:duration="500" />
<item android:drawable="@drawable/firefox_animation_1"
android:duration="500" />
</animation-list>
xml文件名可以自用定义;根元素是animation-list,要有多个item元素。
2、在main.xml中创建ImageView组件,并且设置Background
<ImageView android:layout_width="wrap_content"
android:background="@anim/firefox_animation"
android:layout_height="wrap_content" android:id="@+id/ImageView01" />
3、在Java代码中获取ImageView对象,然后ImageView对象获取AnimationDrawable
AnimationDrawable ad = (AnimationDrawable) imgView.getBackground();
4、AnimationDrawable对象启动或停止。
ad.start();
ad.stop();
Android 逐帧动画的小例子
最新推荐文章于 2022-07-02 11:20:32 发布