android 顯示gif圖片執行個體詳解_Android

來源:互聯網
上載者:User

在android中不支援gif格式的圖片,但是由於我希望在我的程式中剛剛載入的時候有一個小人在跑步表示正在載入。而這個小人跑就是一個gif圖片。也就是希望程式一啟動時就載入gif圖片。在網上尋找了一些方法不知道是我使用的android的版本高(android4.4)還是什麼問題就是載入不出來。最後想了一個辦法載入了出來。這個辦法就是將gif放在webView中讓其顯示。

下面是關於這個的代碼:

activity_prepare_fullscreen.xml檔案

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:tools="http://schemas.android.com/tools"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:background="#F3F3F3"   >  <WebView    android:id="@+id/runWebView"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_centerHorizontal="true"    android:layout_centerVertical="true" />  <TextView    android:id="@+id/fullscreen_content"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_below="@+id/runWebView"    android:layout_centerHorizontal="true"    android:gravity="center"    android:keepScreenOn="true"    android:text="正在載入請等待..."    android:textColor="#33b5e5"    android:textSize="30sp"    android:textStyle="bold" /></RelativeLayout>

PrepareFullscreenActivity.java 檔案

多餘的就不貼了,這是主要的兩句

private WebView runWebView=null;

runWebView = (WebView) findViewById(R.id.runWebView);

下一句就是放入檔案,檔案在assents下放著呢

runWebView.loadDataWithBaseURL(null,"<HTML><body bgcolor='#f3f3f3'><div align=center><IMG src='file:///android_asset/run.gif'/></div></body></html>", "text/html", "UTF-8",null);

希望通過本文,能協助大家解決這種問題,謝謝大家對本站的支援!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.