1

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.

androidgeek
  • 3,440
  • 1
  • 15
  • 27

1 Answers1

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