Android动画之图片动画(四)

现在使ImageView中的图片可以动起来

1.在drawable-mdpi文件夹下加入图片,并加入一个xml文件,文件如下

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
  <item android:drawable="@drawable/a" android:duration="500"/> 
  <item android:drawable="@drawable/b" android:duration="500"/> 
  <item android:drawable="@drawable/c" android:duration="500"/> 
  <item android:drawable="@drawable/d" android:duration="500"/> 

</animation-list>


2.代码如下

iv.setBackgroundResource(R.drawable.anim);
			AnimationDrawable an=(AnimationDrawable)iv.getBackground();
			an.start();


其实可以用一个线程加Handler来实现动画的,在线程中隔一定时间发送消息,更改ImageView的图片。

你可能感兴趣的:(android,xml,encoding)