GIF Image display using WebView

后端 未结 8 798
北荒
北荒 2020-12-08 23:11

Can someone please provide a code to display GIF images in a webview ( I\'m already able to display the same using frame animation of png images) Now I want a way to display

相关标签:
8条回答
  • 2020-12-08 23:30

    Try this..

    WebView wv = (WebView) findViewById(R.id.webView1);
    wv.loadUrl("file:///android_asset/anim5.gif");
    

    Simply call your GIF image from assets like this..

    0 讨论(0)
  • 2020-12-08 23:31

    This is the best solution for GIF in Android :

    Insert the following dependency to build.gradle file of your project.

    dependencies {
        compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.+'
    }
    

    then

    The simplest way is to use GifImageView 
    
    <pl.droidsonroids.gif.GifImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/src_anim"
        android:background="@drawable/bg_anim"
        />
    

    If drawables declared by android:src and/or android:background are GIF files then they will be automatically recognized as GifDrawables and animated. If given drawable is not a GIF then mentioned Views work like plain ImageView and ImageButton.

    https://github.com/koral--/android-gif-drawable

    0 讨论(0)
  • yes this is the right that gif not support in android Another solution As TRonZ WebView supports gif , just make a WebView and load the URL of the gif image and you are done

    0 讨论(0)
  • 2020-12-08 23:36

    Loads gif in a webview and fits it to the device screen without any HTML code...Try this code

    mWebView = ((CustomWebView)mRootView.findViewById(R.id.webview));
    mWebView.loadUrl("file:///android_asset/file.gif");
    mWebView.getSettings().setLoadWithOverviewMode(true);
    mWebView.getSettings().setUseWideViewPort(true);
    
    0 讨论(0)
  • Save your GIF file at Assets folder. Here "loading.gif" is the filename.

        WebView webView=new WebView();
        Content = webView;
    
        webView.Source = new HtmlWebViewSource
        {
            Html = $"<body\"><img src=\"loading.gif\"/></body>"
        };
    
    0 讨论(0)
  • 2020-12-08 23:52

    You do not need any HTML code... Just use this line

    webViewControl.LoadUrl("file://" + pathToTheGifFile);
    

    It Works for Me.

    0 讨论(0)
提交回复
热议问题