• Android学习笔记 5. ProgressBar


    Android学习笔记

    Android基础开发——控件

    5. ProgressBar

    5.1 主要属性
    属性含义
    max进度条的最大值
    progress进度条已完成进度值
    indeterminatetrue:进度条不精确显示进度
    style=“?android:attr/progressBarStyleHorizontal”水平进度条
    5.2 属性演示

    基本样式

    在这里插入图片描述

    使用按钮实现进度条的显示与隐藏

    package com.dingjiaxiong.myprogressbar;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.os.Bundle;
    import android.view.MotionEvent;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ProgressBar;
    
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            ProgressBar progressBar = findViewById(R.id.prob);
            Button button = findViewById(R.id.btn);
    
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(progressBar.getVisibility() == view.GONE){
                        progressBar.setVisibility(view.VISIBLE);
                    }else{
                        progressBar.setVisibility(view.GONE);
                    }
                }
            });
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    
    
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        >
    
        <ProgressBar
            android:id="@+id/prob"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />
    
        <Button
            android:id="@+id/btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="显示隐藏进度条"
            />
    
    
    LinearLayout>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    在这里插入图片描述

    在这里插入图片描述

    水平进度条模拟增加

    btn_load.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            int progress = pro2.getProgress();
            progress += 10;
            pro2.setProgress(progress);
        }
    });
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    在这里插入图片描述

  • 相关阅读:
    5G工业网关的科技治超应用 超限超重超速非现场联合执法
    青少年软件编程C++二级真题(202106)
    Helm 的简单使用 wordpress install
    PAT乙级 1101 B是A的多少倍 C语言实现
    查看双翌视觉软件版本号
    javaSwing销售管理
    C++统一初始化和初始化列表
    HOOK Native API
    dart特殊符号语法(一)
    【OpenCV-Python】教程:3-14 Hough 圆变换
  • 原文地址:https://blog.csdn.net/weixin_44226181/article/details/126206152