2016-07-06 57 views
1

我正在使用正常圖像視圖來顯示來自我的服務器的圖像,現在我想要顯示gif動畫,但不知道如何去做,請問您能幫我嗎?在android中顯示gifs

+0

參考這個鏈接http://stackoverflow.com/questions/3660209/display-animated-gif –

回答

1

您可以使用一個名爲滑翔庫,檢查此鏈接 https://github.com/bumptech/glide

的依賴添加到您的build.gradle

dependencies { 
    compile 'com.github.bumptech.glide:glide:3.7.0' 
    compile 'com.android.support:support-v4:19.1.0' 
} 

要顯示您的GIF的ImageView使用此示例:

ImageView imageView = (ImageView) findViewById(R.id.imageView); 
Glide.with(context) 
    .load(imageUrl) 
    .asGif() 
    .crossFade() 
    .into(imageView); 
+0

是的,但我不善於使用庫 – user3693698

2

我在我的項目中使用這個庫https://github.com/koral--/android-gif-drawable
它在RecyclerView中完美工作。

使用庫是非常簡單,只需添加

compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.16' 

的build.gradle文件 ,並用它在你的佈局像這樣

<pl.droidsonroids.gif.GifImageView 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:src="@drawable/src_anim" 
android:background="@drawable/bg_anim" 
/> 

或者你也可以從使用這樣的代碼:

GifDrawable gifFromPath = new GifDrawable("/path/anim.gif");