当前位置:操作系统 > 安卓/Android >>

Android动画之图片动画(四)

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

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

[html]
<?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> 

<?xml version="1.0" encoding="utf-8"?> www.zzzyk.com
<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.代码如下

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

iv.setBackgroundResource(R.drawable.anim);
   AnimationDrawable an=(AnimationDrawable)iv.getBackground();
   an.start();
其实可以用一个线程加Handler来实现动画的,在线程中隔一定时间发送消息,更改ImageView的图片。

分享到:

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,