SeekBar进度条的使用

一、在Xml布局中

<SeekBar
android:id="@+id/mSeekBar"
android:layout_width="match_parent"
android:layout_height="match_parent" />
二、在Activity中
 
private int a;
@SuppressLint("HandlerLeak")
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what == 0) {
Integer obj = (Integer) msg.obj;
//设置当前进度
mSeekBar.setProgress(obj);
if (obj != 100) {
//隐藏进度条
mSeekBar.setVisibility(View.VISIBLE);
mImageView.setVisibility(View.GONE);
mEditText1.setVisibility(View.GONE);
mEditText2.setVisibility(View.GONE);
} else {
mSeekBar.setVisibility(View.GONE);
mImageView.setVisibility(View.VISIBLE);
mEditText1.setVisibility(View.VISIBLE);
mEditText2.setVisibility(View.VISIBLE);
mL1.setVisibility(View.VISIBLE);
mL2.setVisibility(View.VISIBLE);
}

}
}
};
 
new Thread(new Runnable() {
@Override
public void run() {
a = 0;

for (int i = 0; i < 10; i++) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
a += 10;
mSeekBar.setProgress(a);
handler.sendMessage(handler.obtainMessage(0, a));
}
}
}).start();

你可能感兴趣的:(SeekBar进度条的使用)