ProgressBar是Android的進度條。體驗效果

下面詳細介紹ProgressBar
一、說明
在某些操作的進度中的可視訓示器,為使用者呈現操作的進度,還它有一個次要的進度條,用來顯示中間進度,如在流媒體播放的緩沖區的進度。一個進度條也可不确定其進度。在不确定模式下,進度條顯示循環動畫。這種模式常用于應用程式使用任務的長度是未知的。
二、XML重要屬性
android:progressBarStyle:預設進度條樣式
android:progressBarStyleHorizontal:水準樣式
三、重要方法
getMax():傳回這個進度條的範圍的上限
getProgress():傳回進度
getSecondaryProgress():傳回次要進度
incrementProgressBy(int diff):指定增加的進度
isIndeterminate():訓示進度條是否在不确定模式下
setIndeterminate(boolean indeterminate):設定不确定模式下
setVisibility(int v):設定該進度條是否可視
四、重要事件
onSizeChanged(int w, int h, int oldw, int oldh):當進度值改變時引發此事件
五、執行個體
1.布局檔案
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:max="100"
android:progress="50"
android:secondaryProgress="75" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="預設進度條" />
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="減少" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="增加" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="自定義進度條" />
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第二減少" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第二增加" />
2.Java代碼
package wjq.WidgetDemo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ProgressBar;
public class ProgressBarDemo extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.probarpage);
setProgressBarVisibility(true);
final ProgressBar progressHorizontal = (ProgressBar) findViewById(R.id.progress_horizontal);
setProgress(progressHorizontal.getProgress() * 100);
setSecondaryProgress(progressHorizontal.getSecondaryProgress() * 100);
Button button = (Button) findViewById(R.id.increase);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
progressHorizontal.incrementProgressBy(1);
// Title progress is in range 0..10000
setProgress(100 * progressHorizontal.getProgress());
}
});
button = (Button) findViewById(R.id.decrease);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
progressHorizontal.incrementProgressBy(-1);
// Title progress is in range 0..10000
setProgress(100 * progressHorizontal.getProgress());
}
});
button = (Button) findViewById(R.id.increase_secondary);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
progressHorizontal.incrementSecondaryProgressBy(1);
// Title progress is in range 0..10000
setSecondaryProgress(100 * progressHorizontal.getSecondaryProgress());
}
});
button = (Button) findViewById(R.id.decrease_secondary);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
progressHorizontal.incrementSecondaryProgressBy(-1);
// Title progress is in range 0..10000
setSecondaryProgress(100 * progressHorizontal.getSecondaryProgress());
}
});
}
}