2012-03-09 19 views
1

我的問題是關於這個帖子在Android動態壁紙使用.gif文件

Is it possible to set an animated gif file as live wallpaper in android?

在這篇文章中給出的似乎不工作的方法。當我將我的動畫.gif文件放在/ res/raw文件夾中時,出現錯誤,說明我的文件無法解析或不是字段。有什麼我應該知道的原始文件夾中的資源或有其他一些問題。以下是代碼。

BelleEngine()拋出IOException異常{

 InputStream is = getResources().openRawResource(R.raw.ballerina); 
     if (is != null) { 
      try { 
       mBelle = Movie.decodeStream(is); 
       mBelleDuration = mBelle.duration(); 
      } finally { 
       is.close(); 
      } 
     } else { 
      throw new IOException("Unable to open R.raw.belle"); 
     } 

感謝您的幫助提前!

回答

0

我試過它爲我工作的例子。此外,我已經嘗試過不同的.gif圖像,它似乎並不是他們的任何問題。我的代碼是。 {

/** 
    * Method to init suitable wallpaper according to time. 
    */ 
    private void initWallpaperAccordingtoTime(InputStream inputStream) { 

     if (inputStream != null) { 
      try { 
       wallpaperGifStream = Movie.decodeStream(inputStream); 
       if (wallpaperGifStream != null) { 
        duration = wallpaperGifStream.duration(); 
       } 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } finally { 
       try { 
        inputStream.close(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
      } 
     } 

    } 

調用此方法將是如下。

initWallpaperAccordingtoTime(getResources().openRawResource(
      R.raw.android_apple)); 

}