赞
踩
页面上有一个进度条,10S让进度条自动完成
- <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>
ProgressBar有两个子类:SeekBar--------------------可拖拽性的进度条,一般用来调节系统音量屏幕亮度等
为RatingBar添加监听器
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。