seekbar.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="这是一个滑块的案例"/>
<SeekBar android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/seekBar"
android:max="100"/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="这是一个水平进度条的案例"/>
<ProgressBar android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/firstBar"
android:max="100"
style="?android:attr/progressBarStyleHorizontal"/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="这是一个循环进度条的案例"/>
<ProgressBar android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/secondBar"
android:max="100"
android:progress="10"
style="?android:attr/progressBarStyle"/>
<Button android:layout_width="100px"
android:layout_height="wrap_content"
android:id="@+id/bt_Begn"
android:text="开始"/>
</LinearLayout>
ProgressBarActivity.java文件:
package com.example.baseexample;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.SeekBar;
public class ProgressBarActivity extends Activity {
private SeekBar seekBar;
private ProgressBar firstBar;
private ProgressBar secondBar;
private Button bt_Begin;
private int i=0;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.seekbar);
seekBar= (SeekBar)findViewById(R.id.seekBar);
firstBar = (ProgressBar)findViewById(R.id.firstBar);
secondBar = (ProgressBar)findViewById(R.id.secondBar);
bt_Begin = (Button)findViewById(R.id.bt_Begn);
bt_Begin.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
if(i==0){
firstBar.setVisibility(View.VISIBLE);
secondBar.setVisibility(View.VISIBLE);
}else if(i<=100){
firstBar.setProgress(i);
firstBar.setSecondaryProgress(i+10);
secondBar.setProgress(i);
}
i=i+10;
seekBar.setProgress(i);
}
});
}
}