I want to fetch the image from server through web service and displayed in my app. So how to use Gif images directly from drawable or from web service.
Asked
Active
Viewed 685 times
1
-
i would suggest you to use glide library – Pramod Yadav Apr 07 '15 at 11:09
-
`ImageView` can display GIF files just fine AFAIK. What it cannot do is display animated GIFs, and for that, there are [many libraries](https://android-arsenal.com/search?q=gif). – CommonsWare Apr 07 '15 at 11:11
1 Answers
1
In my opinion webview is best for gif image to load. You can do it easily by extending the WebView.
Step-1 //create a class
public class MyGifView extends WebView {
public MyGifView(Context context, String path) {
super(context);
loadUrl(path);
}
}
Step-2 In your Activity
//If it is an url
MyGifView myGifView = new MyGifView(this, "http://www.picgifs.com/animal-graphics/animal-graphics/kangaroo/animal-graphics-kangaroo-363368.gif");
//If gif image in assets folder
MyGifView view = new MyGifView(this, "file:///android_asset/mygif.gif");
//If gif image in drawable folder
MyGifView view = new MyGifView(this, "file:///android_res/drawable/mygif.gif");
yourlayout.addView(myGifView); //add to desire layout
OR
setContentView(myGifView); //add to content view

Chandra Sharma
- 1,339
- 1
- 12
- 26