ProgressBar
ProgressBar 既进度条,当我们在做一些耗时操作的时候(例如下载文件),可以使用ProgressBar给用户提供一个进度提示,告诉用户当前的进度。ProgressBar提供了两种进度显示模式,分别是具有进度值的精确模式和不具有进度值的模糊模式。
在默认情况下,进度条一般是水平的,但是你可以通过将fillDirection选项设置为向北或向南,来将它设置为垂直的。
Private Sub Command1_Click()
Dim Counter As Integer
Dim Workarea(250) As String
ProgressBar1.Min = LBound(Workarea)
ProgressBar1.Max = UBound(Workarea)
ProgressBar1.Visible = True
//设置进度的值为 Min。
ProgressBar1.Value = ProgressBar1.Min
//在整个数组中循环。
For Counter = LBound(Workarea) To UBound(Workarea)
//设置数组中每项的初始值。
Workarea(Counter) = "Initial value" & Counter
ProgressBar1.Value = Counter
Next Counter
ProgressBar1.Visible = False
ProgressBar1.Value = ProgressBar1.Min
End Sub
Private Sub Form_Load()
ProgressBar1.Align = vbAlignBottom
ProgressBar1.Visible = False
Command1.Caption = "Initialize array"
End Sub
实例:
Java代码片段:
private ProgressBar pb_progressbar_bar;
private TextView tv_progressbar_num;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.progressbar);
pb_progressbar_bar = (ProgressBar) findViewById(R.id.pb_progressbar_bar);
tv_progressbar_num = (TextView) findViewById(R.id.tv_progressbar_num);
}
/**
* ANR
* application not responsing 应用程序未响应
* why:在主线程中执行了耗时的操作
* how:在子线程中执行耗时操作
* @param view
*/
public void download(View view){
new MyThread().start();
}
Handler handler=new Handler(){
//接受消息,更新UI界面
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
int i=msg.what;
tv_progressbar_num.setText(i+"");
}
};
class MyThread extends Thread{
@Override
public void run() {
super.run();
for (int i = 0; i <=100 ; i++) {
pb_progressbar_bar.setProgress(i);
// tv_progressbar_num.setText(i+"");
//在子线程中发消息
handler.sendEmptyMessage(i);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
结果: