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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.