android prograss bar怎么用
发布网友
发布时间:2024-04-23 10:28
我来回答
共1个回答
热心网友
时间:2024-06-18 18:39
<span style="font-size:14px;">import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ProgressBar;
import com.example.android_lb_day2.R;
public class PrograssBarTest extends Activity {
ProgressBar bar;
int current = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_prograssbar);
bar = (ProgressBar) findViewById(R.id.bar);
Thread t = new Thread(able);
t.start();
}
Runnable able = new Runnable() {
@Override
public void run() {
int max = bar.getMax();//获取进度条的最大值
try {
while (max != bar.getProgress()) {
int step = max / 10;
int currentBar = bar.getProgress(); //得到当前进度条
bar.setProgress(step + currentBar);
Thread.sleep(1000);
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
}</span>