五、ProgressBar(进度条)

max:进度条的最大值

progress:进度条已完成进度值

indeterminate:如果设置成true,则进度条不精确显示进度

style="?android:attr/progressBarStyleHorizontal":水平进度条

ui页面源码示例

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
33
34
35
36
37
38
39
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">
 
    <ProgressBar
        android:id="@+id/Pro"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
 
    <!--显示或者隐藏进度条-->
    <Button
        android:text="显示隐藏进度条"
        android:onClick="leoClink"
        android:layout_width="150dp"
        android:layout_height="50dp"/>
 
    <!--添加水平进度条-->
    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:id="@+id/ProShuPing"
        android:max="100"
        android:layout_width="300dp"
        android:layout_height="wrap_content"/>
    <Button
        android:text="模拟下载"
        android:onClick="leoLoad"
        android:layout_width="150dp"
        android:layout_height="50dp"/>
 
    <!--不精确显示进度-->
    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:max="100"
        android:layout_width="300dp"
        android:indeterminate="true"
        android:layout_height="wrap_content"/>
</LinearLayout>

  后台代码示例

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
33
34
35
36
37
38
39
40
41
42
43
package com.example.myprogressbae;
 
import androidx.appcompat.app.AppCompatActivity;
 
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
 
public class MainActivity extends AppCompatActivity {
 
    private  ProgressBar progressBar;
    private  ProgressBar progressBarLoad;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        progressBar = findViewById(R.id.Pro);
 
        progressBarLoad = findViewById(R.id.ProShuPing);
    }
 
    //显示隐藏进度条
    public void leoClink(View view) {
 
        if (progressBar.getVisibility()==View.GONE)
        {
            progressBar.setVisibility(View.VISIBLE);
        }
        else
        {
            progressBar.setVisibility(View.GONE);
        }
 
    }
 
    //模拟下载
    public void leoLoad(View view) {
        int progress = progressBarLoad.getProgress();
        progress+=10;
        progressBarLoad.setProgress(progress);
    }
}

  效果图片

 

posted @   搬砖工具人  阅读(777)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示