android 仿zarker加载提示

先看下效果图

MyProgressDialog类 加载提示

public class MyProgressDialog extends Dialog {
  public Context context;// 上下文

    public MyProgressDialog(Context context) {
        super(context);
        this.context = context;
    }

    public MyProgressDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        this.context = context;
    }

    public MyProgressDialog(Context context, int theme) {
        super(context, theme);
        this.context = context;
        View view = LayoutInflater.from(context).inflate(R.layout.load, null); // 加载自己定义的布局
        ImageView img_loading = (ImageView) view.findViewById(R.id.img_load);
        RelativeLayout img_close = (RelativeLayout) view.findViewById(R.id.img_cancel);
        RotateAnimation rotateAnimation = (RotateAnimation) AnimationUtils.loadAnimation(context, R.anim.refresh); // 加载XML文件中定义的动画
        img_loading.setAnimation(rotateAnimation);// 开始动画
        setContentView(view);// 为Dialoge设置自己定义的布局
        // 为close的那个文件添加事件
        img_close.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                dismiss();
            }
        });
    }
}

 布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/loadbackgroup"
    android:gravity="center_vertical|center_horizontal"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/tv_msg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dip"
        android:padding="15dip"
        android:text="正在加载 ..."
        android:textColor="#ffffff" />

    <ImageView
        android:id="@+id/img_load"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="10dip"
        android:background="@drawable/loadrefresh"
        android:contentDescription="@string/app_name" />

    <ImageView
        android:id="@+id/img_ling"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:background="@drawable/loadline"
        android:contentDescription="@string/app_name" />

    <RelativeLayout
        android:id="@+id/img_cancel"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:padding="15dip" >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="@drawable/loadcancel"
            android:contentDescription="@string/app_name" />
    </RelativeLayout>

</LinearLayout>

 需要用到的图片

1. loadbackgroup.9.png  

2.loadrefresh.png

3.loadcancel.png

4.loadline.png

styles.xml中加入:

    <style name="CustomDialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowFrame">@null</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
        <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    </style>

    <style name="CustomProgressDialog" parent="@style/CustomDialog">
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowNoTitle">true</item>
    </style>

需要打开加载提示地方加入以下代码:

final MyProgressDialog progressDialog = new MyProgressDialog(MainActivity.this,R.style.CustomProgressDialog);
progressDialog.show();//显示加载提示

 需要关闭加载提示的地方加入:

progressDialog.dismiss(); //关闭加载提示框

 

posted @ 2013-11-08 14:54  无心花  阅读(754)  评论(0)    收藏  举报