現在使ImageView中的圖片可以動起來
1.在drawable-mdpi文件夾下加入圖片,並加入一個xml文件,文件如下
[html]
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="https://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.aiwalls.com
<animation-list xmlns:android="https://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的圖片。
分享到: