
1,创建简单的自定义Dialog
2,设置dialog属性与布局
3,布局里使用结合了animated-rotate 的progress
1,创建简单的自定义Dialog
- public class LoadDia extends Dialog {
-
-
- public LoadDia(@NonNull Context context, int themeResId) {
- super(context, R.style.LoadDiaStyle);
- }
-
- protected LoadDia(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
- super(context, cancelable, cancelListener);
- }
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.load_view);
- setCancelable(true);//设置点击dialog外部 不可取消
- setCanceledOnTouchOutside(true);//设置点击dialog外部 不可取消
- }
-
- }
2,设置dialog属性与布局
style文件:
- <style name="LoadDiaStyle" parent="@android:style/Theme.Dialog">
- <item name="android:windowBackground">@android:color/transparentitem>
- <item name="android:windowNoTitle">trueitem>
- <item name="android:windowFrame">@nullitem>
- <item name="android:windowIsFloating">trueitem>
- <item name="android:backgroundDimEnabled">falseitem>
- <item name="android:windowSoftInputMode">adjustNothingitem>
-
- <item name="android:windowIsTranslucent">falseitem>
-
- <item name="android:windowContentOverlay">@nullitem>
-
- style>
布局文件:
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/spe_dia_load"
- android:orientation="vertical">
-
- <ProgressBar
- android:layout_centerHorizontal="true"
- android:id="@+id/loadpro"
- android:layout_width="@dimen/dp_34"
- android:layout_height="@dimen/dp_34"
- android:indeterminateBehavior="repeat"
- android:indeterminateDrawable="@drawable/spe_dia_load_view"
- android:layout_marginTop="@dimen/dp_15" />
-
- <TextView
- android:layout_below="@+id/loadpro"
- android:layout_centerHorizontal="true"
- android:id="@+id/loadDes"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginBottom="@dimen/dp_9"
- android:layout_marginEnd="@dimen/dp_19"
- android:layout_marginStart="@dimen/dp_19"
- android:layout_marginTop="@dimen/dp_9"
- android:text="@string/http_loading"
- android:textColor="@android:color/white"
- android:textSize="@dimen/sp_13" />
- RelativeLayout>
重点就是这个:
3,布局里使用结合了animated-rotate 的progress
spe_dia_load_view:
- <animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
- android:drawable="@drawable/rot_load"
- android:pivotX="50%"
- android:pivotY="50%" />
里面是一个普通的图片png文件~
rot_load:
页面需要使用时:
简单的菊花loading完成
-------------------------end---------------------------------
另外一种 圆圈旋转动画

- <animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
- android:fromDegrees="0"
- android:pivotX="50%"
- android:pivotY="50%"
- android:toDegrees="360">
-
-
- <shape
- android:innerRadius="8dp"
- android:shape="ring"
- android:thickness="3dp"
- android:useLevel="false">
- <gradient
- android:centerY="0.50"
- android:endColor="#cccccc"
- android:startColor="@color/white"
- android:type="sweep"
- android:useLevel="false" />
- shape>
-
-
-
- animated-rotate>