安卓 使用webview加載gif格式動畫


這一篇寫使用webview加載gif動畫,

貼代碼:

xml:

<LinearLayout
  android:layout_width="wrap_content"
  android:layout_height="match_parent"
  android:layout_below="@+id/buttons"
  android:layout_marginTop="20dp"
  android:gravity="center">

  <WebView
    android:id="@+id/webView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
  />
</LinearLayout>

這是布局中的某一個控件

----------------------------------------------------------

activity中調用:

mWebView = (WebView) findViewById(R.id.webView1);

String gifFilePath = "file:///android_asset/1.gif";//首先將一張gif格式的動圖放置在assets中

mWebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);

String data = "<HTML><Div align=\"center\" margin=\"0px\"><IMG src=\"" + gifFilePath + "\" margin=\"0px\"/></Div>";//設置圖片位於webview的中間位置

mWebView.loadDataWithBaseURL(gifFilePath, data, "text/html", "utf-8", null);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM