LoadingView.java 2.05 KB
package com.prws.common.view;

import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.prws.common.R;

/**
 * 加载中的view
 */
public class LoadingView extends ProgressDialog {
    private Context mContext;
    private View loadingView;
    private WindowManager.LayoutParams params;
    private String title;


    public LoadingView(Context context) {
        super(context);
        mContext=context;
    }
    public LoadingView(Context context, int theme) {
        super(context, theme);
        mContext=context;
    }
    public LoadingView(Context context, int theme,String str) {
        super(context, theme);
        mContext=context;
        title=str;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init(mContext);
    }

    private void init(Context context) {
        setCancelable(true);
        setCanceledOnTouchOutside(false);
//        setContentView(R.layout.layout_null);
//        params= getWindow().getAttributes();
//        params.width = WindowManager.LayoutParams.WRAP_CONTENT;
//        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
//        getWindow().setAttributes(params);
//        loadingView=View.inflate(context,R.layout.loading,null);
//        AnimationDrawable animationDrawable = (AnimationDrawable) loadingView.findViewById(R.id.loading_iv).getBackground();
//        if (title != null)
//            ((TextView)loadingView.findViewById(R.id.load_dialog_tv)).setText(title);
//        //判断是否在运行
//        if(!animationDrawable.isRunning()){
//            //开启帧动画
//            animationDrawable.start();
//        }
        addContentView(loadingView,params);
    }




    public LoadingView showDialog() {
        super.show();
        return this;
    }

    @Override
    public void dismiss() {//关闭
        super.dismiss();
    }

}