控件ProgressBar

控件ProgressBar,第1张

概述目录常用属性详解案例常用属性详解1.android:max进度条的最大值2.android:progress进度条已完成进度值3.android:indeterminate如果设置成true,则进度条不精确显示进度4.style="?android:attr/progressBarStyleHorizontal"水平进度条案例activity_main.xml<?

目录常用属性详解案例

常用属性详解

1.androID:max 进度条的最大值
2.androID:progress 进度条已完成进度值
3.androID:indeterminate 如果设置成true,则进度条不精确显示进度
4. 水平进度条

案例

activity_main.xml

<?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/pb1"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"/>    <button        androID:text="显示隐藏进度条"        androID:onClick="FinnyOnClick"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"/>    <Progressbar        androID:ID="@+ID/pb2"        androID:max="100"        androID:progress="0"                androID:layout_wIDth="200dp"        androID:layout_height="wrap_content"/>    <button        androID:text="模拟下载+"        androID:onClick="load"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"/>    <button        androID:text="模拟下载-"        androID:onClick="download"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"/>    <Progressbar        androID:ID="@+ID/pb3"        androID:max="100"        androID:indeterminate="true"                androID:layout_wIDth="200dp"        androID:layout_height="wrap_content"/></linearLayout>

MainActivity.java

package com.example.progressbar;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 progressbar2;    private Progressbar progressbar3;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        progressbar = findVIEwByID(R.ID.pb1);        progressbar2 = findVIEwByID(R.ID.pb2);        progressbar3 = findVIEwByID(R.ID.pb3);    }    public voID FinnyOnClick(VIEw vIEw) {        //如果progressbar是隐藏的        if(progressbar.getVisibility() == VIEw.GONE){            //让他显示出来            progressbar.setVisibility(VIEw.VISIBLE);        }else{            //如果不是隐藏的,让他隐藏            progressbar.setVisibility(VIEw.GONE);        }        //水平进度条        if(progressbar2.getVisibility() == VIEw.GONE){            progressbar2.setVisibility(VIEw.VISIBLE);        }else{            progressbar2.setVisibility(VIEw.GONE);        }        //水平进度条,不精确显示进度的进度条        if(progressbar3.getVisibility() == VIEw.GONE){            progressbar3.setVisibility(VIEw.VISIBLE);        }else{            progressbar3.setVisibility(VIEw.GONE);        }    }    public voID load(VIEw vIEw) {        int progress = progressbar2.getProgress();        progress += 10;        progressbar2.setProgress(progress);    }    public voID download(VIEw vIEw) {        int progress = progressbar2.getProgress();        progress -= 10;        progressbar2.setProgress(progress);    }}

总结

以上是内存溢出为你收集整理的控件ProgressBar全部内容,希望文章能够帮你解决控件ProgressBar所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/999706.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存