Display Animated GIF

后端 未结 30 2546
无人及你
无人及你 2020-11-22 02:11

I want to display animated GIF images in my aplication. As I found out the hard way Android doesn\'t support animated GIF natively.

However it can display animations

30条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 02:52

    There are two options to load animated gifs into our Android apps

    1)Using Glide to load the gif into an ImageView.

        String urlGif = "https://cdn.dribbble.com/users/263558/screenshots/1337078/dvsd.gif";
        //add Glide implementation into the build.gradle file.
        ImageView imageView = (ImageView)findViewById(R.id.imageView);
        Uri uri = Uri.parse(urlGif);
        Glide.with(getApplicationContext()).load(uri).into(imageView);
    

    2) Using an html to load the gif into a WebView

    Create the html with the address to the .gif file:

    
    
    
    
    
    

    store this file into the assets directory:

    The load this html into the WebView of your application:

        WebView webView =  (WebView)findViewById(R.id.webView);
        webView = (WebView) findViewById(R.id.webView);
        webView.loadUrl("file:///android_asset/html/webpage_gif.html");
    

    Heres is a complete example of this two options.

提交回复
热议问题