ProgressBar
1、String.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, ProgressBar test!</string>
<string name="app_name">Activity08</string>
</resources>
2、main.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="@string/hello" />
<ProgressBar
android:id="@+id/firstBar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:visibility="gone" />
<ProgressBar
android:id="@+id/secondBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<Button
android:id="@+id/b"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Begin" />
</LinearLayout>
3、Activity.java
package mars.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
public class Activity08 extends Activity {
/** Called when the activity is first created. */
private ProgressBar firstBar;
private ProgressBar secondBar;
private Button b;
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);
b = (Button) findViewById(R.id.b);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (i == 0) {
firstBar.setVisibility(ProgressBar.VISIBLE);
secondBar.setVisibility(ProgressBar.VISIBLE);
} else if (i < 100) {
firstBar.setProgress(i);
firstBar.setSecondaryProgress(i + 10);
} else {
firstBar.setVisibility(View.GONE);
secondBar.setVisibility(View.GONE);
}
i += 10;
System.out.println(i);
// Toast.makeText(Activity08.this, i,
// Toast.LENGTH_SHORT).show();
}
});
}
}