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() 设置该进度条是否可视