我是一名“新鲜”的 Android 开发人员,我尝试了水平 ProgressBar。我有一个小问题,进度在中间停止,直到栏结束才继续。
你能帮我吗?
这是我的代码
progress=0;
mProgress = (ProgressBar) findViewById(R.id.progressBar1);
mProgress.setMax(200);
// Start lengthy operation in a background thread
new Thread(new Runnable()
{
public void run()
{
while (mProgressStatus < 100)
{
mProgressStatus = doWork();
// Update the progress bar
mHandler.post(new Runnable()
{
public void run()
{
mProgress.incrementProgressBy(20);
mProgress.setProgress(mProgressStatus);
}
});
}
// Cache la progressBar
mHandler.post(new Runnable()
{
@Override
public void run()
{
mProgress.setVisibility(4);
}
});
}
//---------------------------------Work to do-----------------------
private int doWork()
{
try{
Thread.sleep(50);//5 secondes
}catch(InterruptedException e)
{
e.printStackTrace();
}
return ++progress;
}
//------------------------------------------------------------------
}).start();
}