5. ProgressBar

5. ProgressBar
5.1 主要属性
属性    含义
max    进度条的最大值
progress    进度条已完成进度值
indeterminate    true:进度条不精确显示进度
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);
                }
            }
        });
    }
}
<?xml version="1.0" encoding="utf-8"?>

<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>

在这里插入图片描述

在这里插入图片描述

水平进度条模拟增加

btn_load.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        int progress = pro2.getProgress();
        progress += 10;
        pro2.setProgress(progress);
    }
});
在这里插入图片描述

posted @ 2022-09-12 16:29  随遇而安==  阅读(20)  评论(0编辑  收藏  举报