2012-12-28 25 views
8

當您需要更改ProgressBar的背景圖像時,需要採取的適當措施是什麼?我的意思是應該使用一個.gif圖像,如:http://2.bp.blogspot.com/-O7nsXfmgwSc/T6PQ0PVr6-I/AAAAAAAAAQI/-eXkEXj24-s/s1600/02.gif,如果是這樣,條的前景色會在進程中填充圖像文件?有沒有爲酒吧的背景創建動畫的方法?我的目標是顯示動畫,只要這個過程不包含完整的欄。Android上的ProgressBar上的背景動畫圖像?

回答

14

您需要將所有此gif幀圖像作爲單獨的,然後設置到xml文件中的動畫列表中。

這是您的anim_progress.xml文件代碼

<?xml version="1.0" encoding="utf-8"?> 
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
    android:oneshot="false"> 
    <item android:drawable="@drawable/i1" android:duration="500" /> 
    <item android:drawable="@drawable/i2" android:duration="500" /> 
    <item android:drawable="@drawable/i3" android:duration="500" /> 
    <item android:drawable="@drawable/i4" android:duration="500" /> 
    <item android:drawable="@drawable/i5" android:duration="500" /> 
    <item android:drawable="@drawable/i6" android:duration="500" /> 
    <item android:drawable="@drawable/i7" android:duration="500" /> 
    <item android:drawable="@drawable/i8" android:duration="500" /> 
</animation-list> 

設置變化平滑效果的持續時間給了動畫形象如GIF

下面是使用此文件

ImageView iv = new ImageView(this); 
iv.setBackgroundResource(R.drawable.anim_progress); 
final AnimationDrawable mailAnimation = (AnimationDrawable) iv.getBackground(); 
iv.post(new Runnable() { 
    public void run() { 
     if (mailAnimation != null) mailAnimation.start(); 
     } 
}); 
代碼

setContentView(iv);

你可以從這個網站的gif文件獲取所有幀。

http://gif-explode.com/

例如

http://2.bp.blogspot.com/-O7nsXfmgwSc/T6PQ0PVr6-I/AAAAAAAAAQI/-eXkEXj24-s/s1600/02.gif

此鏈接只是通過它,你會得到所有的幀圖像

+0

非常感謝,我想這一點,並讓你知道! – JimBoyHac

+0

像冠軍一樣工作! – JimBoyHac

+0

關於如何將ImageView設置爲進度條背景的任何想法? – JimBoyHac