Android帧动画

通过播放一张一张图片来实现一段动画

首先配置anim.xml:

1 <?xml version="1.0" encoding="utf-8"?>
2 <animation-list xmlns:android="http://schemas.android.com/apk/res/android">
3 
4     <item android:drawable="@drawable/a" android:duration="200"/>
5     <item android:drawable="@drawable/b" android:duration="200"/>
6     <item android:drawable="@drawable/c" android:duration="200"/>
7     <item android:drawable="@drawable/d" android:duration="200"/>
8     <item android:drawable="@drawable/e" android:duration="200"/>
9 </animation-list>

然后用一个ImageView显示

1 <ImageView
2         android:id="@+id/iv"
3         android:layout_centerInParent="true"
4         android:onClick="click3"
5         android:clickable="true"
6         android:layout_width="200dp"
7         android:layout_height="200dp" />

再。。。。

1 public void click3(View v){
2         ImageView iv = (ImageView)findViewById(R.id.iv);
3         iv.setBackgroundResource(R.drawable.anim);
4         AnimationDrawable ad = (AnimationDrawable)iv.getBackground();
5         ad.start();
6     }

就是这么简单。。。。

GitHub:https://github.com/godfunc
博客园:http://www.cnblogs.com/godfunc
Copyright ©2019 Godfunc
原文地址:https://www.cnblogs.com/Godfunc/p/6026855.html