Android控件之ProgressBar基本用法

1、ProgressBar控件简介

ProgressBar类的继承关系

java.lang.Object

android.view.View

android.widget.ProgressBar

在某些操作的进度中的可视指示器,为用户呈现操作的进度,它还有一个次要的进度条,用来显示中间进度,如在流媒体播放的缓冲区的进度。

一个进度条的最经常使用的是,其进度不能确定的情况。例如常见的流媒体播放、下载进度等等。

在不确定情况下,进度条显示的是循环动画。这种模式常用于应用程序中的任务长度是未知的。

进度条也可以是一个转动的圆盘,表是运转的过程,例如发短信,连接网络等等,表示一个过程正在执行中。

控件效果图如下:

2、xml布局文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

    <ProgressBar
        android:id="@+id/progressBar3"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/progressBar2" />

    <ProgressBar
        android:id="@+id/progressBar2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/progressBar1" />

    <ProgressBar
        android:id="@+id/progressBar4"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/progressBar3"
        android:max="150"
        android:progress="50"
        android:secondaryProgress="70"/>

</RelativeLayout>
重要属性:

android:max           进度跳的最大值,一般为流媒体的大小、文件大小等

android:progress   当前进度值

android:secondaryProgress     第二进度条
重要方法:

getMax()      得到进度条的最大值

getProgress()    得到当前进度条的值

getSecondaryProgress()   得到第二进度条的值

incrementProgressBy(int diff)   指定进度条每次增加的值,即步长

isIndeterminate(boolean indeterminate)     指定进度条是否在不确定模式下

setVisibility()    设置该进度条是否可视



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值