2011-03-11 55 views
9

您好我特林應用自定義圖像微調Android中我爲此目的而使用.gif文件,我應用它,通過這個代碼進步dialod,如何應用自定義微調圖像進度對話框中的Android

dialog = new ProgressDialog(BackupRestoreActivityContext);  
dialog.setCancelable(true);  
dialog.setIcon(resId);  
dialog.setTitle(title);  
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);  
dialog.setIndeterminate(true); 
dialog.setIndeterminateDrawable(BackupRestoreActivityContext.getResources().getDrawable(R.drawable.bar));  
dialog.show(); 

通過此代碼微調圖像改爲bar.gif,但它不旋轉, 請親切地幫助我這是什麼錯誤,感謝在這方面的任何幫助,不勝感激。

回答

9

在Android中,動畫gif在ImageView中不起作用。您需要按照ApiDemos樣本所示的方式播放它們。

但是你可以在多文件中分解你的gif並創建一個動畫源文件。 動畫文件是一個xml文件,用於描述要顯示的可繪製列表以及每個幀的持續時間(或者如果可以使用它們,則應用轉換)。 http://developer.android.com/guide/topics/resources/animation-resource.html#Frame

這應該繪製的很好,然後在你的ProgressDialog

8

有點晚了我的答案工作,但,你可以這樣做:

1.- 您可以在官方文檔在這裏閱讀詳細製作動畫繪製

例如:my_animation.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/myImage1" 
     android:duration="200"/> 
    <item 
     android:drawable="@drawable/myImage2" 
     android:duration="200"/> 
... 


</animation-list> 

2.-在您的活動電話

dialog = new ProgressDialog(BackupRestoreActivityContext);  
dialog.setCancelable(true);  
dialog.setIcon(resId);  
dialog.setTitle(title);  
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);  
dialog.setIndeterminate(true); 
dialog.setIndeterminateDrawable(BackupRestoreActivityContext.getResources().getDrawable(R.drawable.my_animation)); 
dialog.show(); 
+0

謝謝。在這裏工作。 – statosdotcom 2017-05-22 04:58:17