效果为:这个图形一直在转动
1.方法名
/**
* 创建一个进度框
* @param context
* @param text
* @return
*/
public static Dialog createLoadingDialog(Context context,String text) {
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.loading_dialog, null);
ImageView loadimage = (ImageView) view.findViewById(R.id.loading_image);
Animation animation = AnimationUtils.loadAnimation(context, R.anim.loading);
loadimage.startAnimation(animation);
Dialog dialog = new Dialog(context, R.style.loading_dialog);
dialog.setCancelable(false);
dialog.setContentView(view,new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
return dialog;
}
2.XML文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/loading_image"
android:src="@drawable/loading"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/loading_text"
android:text="正在加载中,请稍候。。。。"/>
</LinearLayout>
3.图片
4.anim动画文件 loading.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate android:interpolator="@android:anim/linear_interpolator" xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="+360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000"
android:repeatCount="-1"
>
</rotate>
5. style
<!-- 自定义loading dialog -->
<style name="loading_dialog" parent="android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@color/loading_bg</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
6.color配置背景
<color name="loading_bg">#00e0e2e1</color>