Reputation: 3480
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.
Upvotes: 1
Views: 691
Reputation: 1340
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
Upvotes: 1