There are libraries for loading animated gifs within an application, but what would be the proper way to load animated gifs without using third-party libraries or custom views?
I had done uploading .gif using WebView
this way:
WebView webView = (WebView)findViewById(R.id.webView);
webView = (WebView) findViewById(R.id.webView);
webView.loadUrl("file:///android_asset/myanimation.gif");
But you also want the .gif to be found in a url and not within the project resources.
There are two options for loading animated gifs in an Android app. using these methods you can load animated gifs from a url.
1) Using Glide to load the animated gif inside a
ImageView
.2) Using an html to load the animated gif inside a
WebView
.Create an html containing the path to the .gif file:
store this .html file inside the directory
/assets
:Now load the html inside a
WebView
in your app:Here is a complete example showing both options .
In your file
gradle
in thedependencies
add part:And in the part of java where you are reading the image, place
It wonders if it is a gif so that it improves the load, by not reading the gif as a gif, they take time to be displayed on the screen.