Android进度条Dialog

本文将介绍如何在Android应用中创建一个自定义的圆形进度条对话框,包括XML布局文件和Java代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//圆形进度条
    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>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值