Android进度条Dialog

//圆形进度条
    public static Dialog createDialog(Context context){
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.loading_dialog, null);
        assert view != null;
        LinearLayout layoutDialog = (LinearLayout) view.findViewById(R.id.dialogView);
        ImageView image = (ImageView) view.findViewById(R.id.dialog_image);
        Animation animation = AnimationUtils.loadAnimation(context, R.anim.loading_dialog);
        if(animation != null){
            image.startAnimation(animation);
        }
        Dialog loadingDialog = new Dialog(context, R.style.customProgressDialog);
        loadingDialog.setCancelable(false);
        loadingDialog.setContentView(layoutDialog, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT
        ));
        return loadingDialog;
    }


布局xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/dialogView"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:gravity="center">


    <ImageView
            android:id="@+id/dialog_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@null"
            android:src="@drawable/state_loading"/>


    <TextView
            android:id="@+id/dilog_textview"
            android:text="@string/loading"
            android:textColor="#ffffff"
            android:textSize="17sp"
            android:gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
</LinearLayout>


旋转图片动画xml:


<set xmlns:android="http://schemas.android.com/apk/res/android">

    <rotate
            android:interpolator="@android:anim/linear_interpolator"
            android:pivotX="50%"
            android:pivotY="50%"
            android:fromDegrees="0"
            android:toDegrees="+360"
            android:duration="1500"
            android:startOffset="-1"
            android:repeatMode="restart"
            android:repeatCount="-1"/>
</set>


你可能感兴趣的:(Android进度条Dialog)