主文件ProgressBar.java:
package com.progress;
import android.app.Activity;
import android.content.DialogInterface;
import android.view.View.OnClickListener;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
public class progress extends Activity {
/** Called when the activity is first created. */
private ProgressBar firstBar=null;
private ProgressBar secondBar=null;
private Button mybutton=null;
private int i=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
firstBar=(ProgressBar)findViewById(R.id.firstBar);
secondBar=(ProgressBar)findViewById(R.id.secondBar);
mybutton=(Button)findViewById(R.id.MyButton);
mybutton.setText("开始");
mybutton.setOnClickListener(new ButtonListener());
}
class ButtonListener implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(0==i){
firstBar.setVisibility(View.VISIBLE);
secondBar.setVisibility(View.VISIBLE);
}else if(i<100){
firstBar.setProgress(i);
firstBar.setSecondaryProgress(i+10);
secondBar.setProgress(i);
}else{
firstBar.setVisibility(View.GONE);
secondBar.setVisibility(View.GONE);
}
i=i+10;
}
}
}
主要配置文件:main.xml
<?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/firstBar" style="?android:attr/progressBarStyleHorizontal" android:layout_width="200dp" android:layout_height="wrap_content" android:visibility="gone" /> <ProgressBar android:id="@+id/secondBar" style="?android:attr/progressBarStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" /> <Button android:id="@+id/MyButton" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>