Android控制元件之ProgressBar基本用法
阿新 • • 發佈:2019-02-06
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() 設定該進度條是否可視