<?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="wrap_content"
android:layout_height="wrap_content"
android:text="默認進度條"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="progress1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="小圓形進度條"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="progress2"
style="?android:attr/progressBarStyleSmall"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="大圓形進度條"
android:layout_gravity="center_vertical"
/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="progress3"
style="?android:attr/progressBarStyleLarge"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="條形進度條"
/>
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="progress4"
android:id="@+id/pb"
style="?android:attr/progressBarStyleHorizontal"
android:max="100"
android:progress="50"
android:secondaryProgress="70"
/>
</LinearLayout>
。。。。。。、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ProgressBar;
public class MainActivity extends Activity implements Runnable{
private Thread th;//聲明一條線程
private ProgressBar pb;//聲明一個進度條對象
private boolean stateChage;//標識進度值最大最小的狀態
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//實例進度條對象
pb=(ProgressBar) findViewById(R.id.pb);
th=new Thread(this);//實例線程對象
th.start();
}
@Override
public void run() {//實現Runnable接口抽象函數
while(true){
int current=pb.getProgress();//得到當前進度值
int currentMax=pb.getMax();//得到進度條的最大進度值
int seCurrent=pb.getSecondaryProgress();//得到底層當前進度值
//以下代碼實現進度值越來越大 越來越小的一個動態效果
if(stateChage==false){
if(current>=currentMax){
stateChage=true;
}else{
//設置進度值
pb.setProgress(current+1);
//設置底層進度值
pb.setSecondaryProgress(current+1);
}
}else{
if(current<=0){
stateChage=false;
}else{
pb.setProgress(current-1);
}
}
try{
Thread.sleep(50);
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
}