2011-05-07 32 views
2

如果任何人都可以幫助,我會非常感激。基本上我想獲得這個動畫GIF或任何它需要的,以顯示爲按鈕背景。當我點擊按鈕時,我希望它變成這個動畫,顯示一個微調旋轉。任何想法如何讓這個動畫GIF作爲一個可繪製的按鈕背景工作?我需要使這個動畫顯示爲一個按鈕背景

+0

請參閱http://stackoverflow.com/questions/5918475/changing-a-buttons-background-image-through-using-a-random-array – trashgod 2011-05-07 01:48:55

+0

如果答案對您有用,請考慮將一些答案標記爲已接受在你的其他問題。 – Aleadam 2011-05-07 01:52:01

回答

4

這是我該怎麼做的。首先拆分GIF並將每個圖像添加到您的可繪製文件夾中。然後,新的XML文件添加到您的繪製(animation.xml)....見下面的例子

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
android:oneshot="false"> 
<item android:drawable="@drawable/santa1" android:duration="200" /> 
<item android:drawable="@drawable/santa2" android:duration="200" /> 
<item android:drawable="@drawable/santa3" android:duration="200" /> 
<item android:drawable="@drawable/santa4" android:duration="200" /> 
<item android:drawable="@drawable/santa5" android:duration="200" /> 
<item android:drawable="@drawable/santa6" android:duration="200" /> 
<item android:drawable="@drawable/santa7" android:duration="200" /> 

</animation-list> 

然後,當你想讓它開始與下面這個例子叫它....

b_1.setBackgroundResource(R.drawable.animation); 
         AnimationDrawable b1Amin = (AnimationDrawable) b_1.getBackground(); 
         b1Amin.start();