现在使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应用中通过ImageView展示动画效果。具体步骤包括:在drawable-mdpi文件夹下创建包含多个帧的动画图片资源,并使用XML定义动画列表;在Activity中通过AnimationDrawable播放动画。
1767

被折叠的 条评论
为什么被折叠?



