• Android原生控件 -- ProgressBar(进度加载) & ProgressDialog(进度展示对话框)


    ⒈ProgressBar使用

      默认

        <ProgressBar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            style="@android:style/Widget.Material.ProgressBar"/>

      设置是否可见

        <ProgressBar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            style="@android:style/Widget.Material.ProgressBar"
            android:visibility="visible"/>

      水平的进度条

        <ProgressBar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            style="@android:style/Widget.ProgressBar.Horizontal"/>

      添加总进度、当前进度及二级进度(给人一种缓存的感觉)

        <ProgressBar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            style="@android:style/Widget.ProgressBar.Horizontal"
            android:max="100"
            android:progress="10"
            android:secondaryProgress="30"/>    

      模拟进度

    package cn.coreqi.helloworld2;
    
    
    import androidx.annotation.NonNull;
    import androidx.appcompat.app.AppCompatActivity;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    import android.widget.ProgressBar;
    import android.widget.Toast;
    
    
    public class MainActivity extends AppCompatActivity {
    
        private ProgressBar mPb1;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mPb1 = findViewById(R.id.pb1);
            handler.sendEmptyMessage(0);
        }
        Handler handler = new Handler(){
            @Override
            public void handleMessage(@NonNull Message msg) {
                super.handleMessage(msg);
                if(mPb1.getProgress() < 100){
                    handler.postDelayed(runnable,500);
                }else {
                    Toast.makeText(getApplicationContext(),"加载完成",Toast.LENGTH_LONG).show();
                }
            }
        };
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                mPb1.setProgress(mPb1.getProgress() + 5);
            }
        };
    }

      设置自定义进度图片旋转

    <?xml version="1.0" encoding="utf-8"?>
    <animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
        android:drawable="@drawable/icon_progress"
        android:pivotX="50%"
        android:pivotY="50%">
    
    </animated-rotate>
        <ProgressBar
            android:id="@+id/pb1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:indeterminateDrawable="@drawable/bg_progress"/>

    ⒉ProgressDialog使用

      普通用法

            ProgressDialog progressDialog = new ProgressDialog(getApplicationContext());
            progressDialog.setTitle("提示");
            progressDialog.setMessage("正在加载");
            progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    
                }
            });
            //progressDialog.setCancelable(false);    
            progressDialog.show();

      进度条用法

            ProgressDialog progressDialog = new ProgressDialog(getApplicationContext());
            progressDialog.setTitle("提示");
            progressDialog.setMessage("正在下载");
            progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
    
                }
            });
            //progressDialog.setCancelable(false);
            progressDialog.show();

      添加按钮

            ProgressDialog progressDialog = new ProgressDialog(getApplicationContext());
            progressDialog.setTitle("提示");
            progressDialog.setMessage("正在下载");
            progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
    
                }
            });
            progressDialog.setButton(DialogInterface.BUTTON_POSITIVE, "后台进行", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    
                }
            });
            //progressDialog.setCancelable(false);
            progressDialog.show();
  • 相关阅读:
    ubuntu 安装 less
    Django orm增删改字段、建表 ,单表增删改查,Django请求生命周期
    python RabbitMQ队列使用
    80个Python练手项目列表
    celery异步任务体系笔记
    为什么要选择RabbitMQ ,RabbitMQ简介,各种MQ选型对比
    吞吐量(TPS)、QPS、并发数、响应时间(RT)
    Supervisor使用详解
    supervisor 使 celery后台运行
    celery Django 简单示例
  • 原文地址:https://www.cnblogs.com/fanqisoft/p/12162090.html
Copyright © 2020-2023  润新知