在Android中显示gif图片

布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/color_ffffff">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="140dp"
        android:textColor="@color/color_a7a6a6"
        android:gravity="center"
        android:textSize="15dp"
        android:text="@string/exit_kindergarten_success_tips"/>
    <RelativeLayout
        android:id="@+id/rl_exit_kindergarten"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="38dp">
        <WebView
            android:id="@+id/iv_exit_kindergarten"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            />
        <TextView
            android:id="@+id/tv_exit_kindergarten"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/iv_exit_kindergarten"
            android:textSize="16dp"
            android:layout_marginTop="17dp"
            android:layout_centerHorizontal="true"
            android:textColor="@color/color_60b166"
            android:text="@string/exiting_kindergarten"/>

    </RelativeLayout>
    <RelativeLayout
        android:id="@+id/rl_exit_kindergarten_success"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:layout_marginTop="38dp">
        <ImageView
            android:id="@+id/iv_exit_kindergarten_success"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/exit_kindergarten_success"
            android:layout_centerHorizontal="true"/>
        <TextView
            android:id="@+id/tv_exit_kindergarten_success"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/iv_exit_kindergarten_success"
            android:textSize="16dp"
            android:layout_marginTop="17dp"
            android:layout_centerHorizontal="true"
            android:textColor="@color/color_60b166"
            android:text="@string/exit_kindergarten_success"/>
        <Button
            android:id="@+id/bt_repeate_login"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/circle_info_btn_green"
            android:layout_below="@+id/tv_exit_kindergarten_success"
            android:textSize="16dp"
            android:textColor="@color/color_ffffff"
            android:layout_marginLeft="12dp"
            android:layout_marginRight="12dp"
            android:layout_marginTop="72dp"
            android:text="@string/repeat_login"/>
    </RelativeLayout>
</LinearLayout>
代码:

 
 
package com.bbtree.publicmodule.paradise.frg;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.RelativeLayout;

import com.bbtree.publicmodule.R;

import net.hyww.wisdomtree.core.base.BaseFrg;
import net.hyww.wisdomtree.core.utils.LogoutUtils;

/**
 * Created by wuqiqi on 2016/1/15.
 */
public class ExitKindergartenSuccessFrg extends BaseFrg{
    private Button tv_repeat_login;
    private RelativeLayout rl_exit_kindergarten;
    private RelativeLayout rl_exit_kindergarten_success;
    private WebView iv_exit_kindergarte;

    @Override
    public int contentView() {
        return R.layout.frg_exit_kindergarten_success;
    }

    @Override
    public boolean titleBarVisible() {
        return false;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        tv_repeat_login= (Button) findViewById(R.id.bt_repeate_login);
        tv_repeat_login.setOnClickListener(this);
        /*final ExitKindergartentLoadingDialog loadingDialog = ExitKindergartentLoadingDialog.newInstance();
        loadingDialog.show(getChildFragmentManager(),"loading");*/
        rl_exit_kindergarten=(RelativeLayout) findViewById(R.id.rl_exit_kindergarten);
        rl_exit_kindergarten_success=(RelativeLayout) findViewById(R.id.rl_exit_kindergarten_success);

        iv_exit_kindergarte=(WebView) findViewById(R.id.iv_exit_kindergarten);
        //iv_exit_kindergarte.loadDataWithBaseURL(null,"<HTML><body bgcolor='#f3f3f3'><div align=center><IMG src='file:///android_asset/gif.gif'/></div></body></html>", "text/html", "UTF-8",null);
        iv_exit_kindergarte.loadDataWithBaseURL(null,"<HTML><body><div align=center><IMG src='file:///android_asset/gif.gif'/></div></body></html>", "text/html", "UTF-8",null);
        new Handler().postDelayed(new Runnable() {

            public void run() {
                // TODO Auto-generated method stub
               // loadingDialog.dismissAllowingStateLoss();
                rl_exit_kindergarten.setVisibility(View.GONE);
                rl_exit_kindergarten_success.setVisibility(View.VISIBLE);
            }

        }, 2000);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        int id=v.getId();
        if(id==R.id.bt_repeate_login){
            getActivity().finish();
            LogoutUtils.getInstance().logout(mContext, false);
        }
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        iv_exit_kindergarte.loadUrl("about:black");
        iv_exit_kindergarte.stopLoading();
        iv_exit_kindergarte=null;
    }
}

猜你喜欢

转载自blog.csdn.net/wuqiqi1992/article/details/50538885
今日推荐