zoukankan      html  css  js  c++  java
  • Android基础-ProgressBar(进度条)

    ProgressBar的基本属性 

    android:style设置进度条的样式  progressBarStyleHorizontal(水平进度条)

    android:progress = "" 设置进度

    android:max = "" 设置最大值,默认100

    android:indeterminate="true" 设置进度条的间隔

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ff0000"
        android:orientation="vertical"
        tools:context=".ProgressBarActivity">
    
        <!--
            进度条:默认样式是转圈。修改样式需要设置风格
            style 设置风格 progressBarStyleHorizontal(水平进度条)
            android:progress = "" 设置进度
            android:max="" 设置最大值, 默认100
            android:indeterminate="true" 设置进度条
    
    
            -->
        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
        <ProgressBar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            style="?android:attr/progressBarStyleHorizontal"
            android:progress="30"
            android:max="200"/>
    
        <ProgressBar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            style="?android:attr/progressBarStyleHorizontal"
            android:indeterminate="true" />
    
        <ProgressBar
            android:id="@+id/progress"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            style="?android:attr/progressBarStyleHorizontal"
            />
    
    </LinearLayout>

    在实际代码中控件进度条的前进 

    这里使用Thread来设置带延时的进度刷新

    package com.example.uidemo;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.os.Bundle;
    import android.widget.ProgressBar;
    
    public class ProgressBarActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_progress_bar);
    
            final ProgressBar progressBar = findViewById(R.id.progress);
    //        progressBar.setProgress(80);
            //在android中, 4.0以后不能直接在线程中操作控件
            new Thread() {
                @Override
                public void run() {
                    for (int i = 1; i <= 100; i++) {
                        progressBar.setProgress(i);
                        try {
                            Thread.sleep(30);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }.start();
        }
    
    }
  • 相关阅读:
    近来有客户要求用table显示一大串数据,由于滚动后就看不到表头,很不方便,所以想到这个效果。
    js如何取当前日期时间/格式为:yyyymmdd hh:mm:ss
    jdk源码分析 – Thread线程类源码分析
    Swing中的MVC
    编程生涯的一次思想总结
    怎样成为高手
    浅谈测试驱动开发(TDD)
    Java RMI之HelloWorld篇(EJB都是建立在rmi基础之上的)
    Swing框架之Model
    EJB 工作原理
  • 原文地址:https://www.cnblogs.com/my-love-is-python/p/14521566.html
Copyright © 2011-2022 走看看