1.首先为动画的布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_transparent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/progress_pop_bg"
android:orientation="vertical"
android:padding="30dp">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateDrawable="@anim/anim_progress"
android:indeterminateDuration="1000" />
<TextView
android:id="@+id/tv_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:background="@color/white"
android:text="加载中..."
android:textColor="#f976a8" />
</LinearLayout>
</RelativeLayout>
2.为加载动画的工具类
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import com.js.phoneforplatform.R;
/**
* Created by Administrator on 2016/4/15.
*/
public class ProgressUtils {
private static PopupWindow mPopupWindow;
public static void showProgress(Context context) {
View progressView = LayoutInflater.from(context).inflate(R.layout.layout_progress, null);
showPopupWindow(progressView);
}
private static void showPopupWindow(View popupView) {
mPopupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
mPopupWindow.setFocusable(true);
mPopupWindow.setOutsideTouchable(false);
mPopupWindow.update();
mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
mPopupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);
}
public static void dismissProgress() {
if (mPopupWindow != null && mPopupWindow.isShowing()) {
mPopupWindow.dismiss();
}
}
}
3.调用方法很简单开始加载为
ProgressUtils.
showPopupWindow(this)。停止为ProgressUtils.
dismissProgress();
4.用到的附件:
progress_pop_bg.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="2dp"></corners> <solid android:color="@color/white"></solid> <stroke android:width="1dp" android:color="@color/white"></stroke> </shape>
anim_progress.xml
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/search_buffer" android:pivotX="50%" android:pivotY="50%"> </rotate>
图片