android 顯示gif圖片


在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);


免責聲明!

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



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