package cn.edu.progressbar;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ProgressBar;
public class ProgressBarActivity extends Activity implements Runnable{
/** Called when the activity is first created. */
private ProgressBar pb;
private int i=0;
private Thread td;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
pb=(ProgressBar)this.findViewById(R.id.pb);
td = new Thread(this);
td.start();
}
@Override
public void run() {
// TODO Auto-generated method stub
while(i<=200){
i=i+10;
pb.setProgress(i);
try {
td.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}}
}
再布局文件中,同样,有各种progressbar的样式
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <!-- <ProgressBar android:id="@+id/pb" style="@android:style/Widget.ProgressBar.Horizontal" android:max="200" android:layout_width="fill_parent" android:layout_height="wrap_content" /> --> <!-- <ProgressBar android:id="@+id/pb" style="@android:style/Widget.ProgressBar.Large" android:max="200" android:layout_width="fill_parent" android:layout_height="wrap_content" /> --> <!-- <ProgressBar android:id="@+id/pb" style="@android:style/Widget.ProgressBar.Small" android:max="200" android:layout_width="fill_parent" android:layout_height="wrap_content" /> --> <ProgressBar android:id="@+id/pb" style="@android:style/Widget.ProgressBar.Small" android:max="200" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>