布局部分:
android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Tool Bar" /> android:id="@+id/progressBarOne" android:layout_width="200dp" android:layout_height="wrap_content" style="?android:attr/progressBarStyleHorizontal" android:visibility="gone" /> android:id="@+id/progressBarTwo" android:layout_width="wrap_content" android:layout_height="wrap_content" style="?android:attr/progressBarStyle" android:visibility="gone" />
package com.yajt.component;
import android.R.integer;
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 ProgressBarActivity extends Activity {
private ProgressBar progressBarOne = null;
private ProgressBar progressBarTwo = null;
private Button go = null;
private int i = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
progressBarOne = (ProgressBar)findViewById(R.id.progressBarOne);
progressBarTwo = (ProgressBar)findViewById(R.id.progressBarTwo);
go = (Button)findViewById(R.id.myButton);
go.setOnClickListener(new GoButtonOnclickListener());
}
class GoButtonOnclickListener implements OnClickListener {
@Override
public void onClick(View v) {
if(i == 0) {
progressBarOne.setVisibility(v.VISIBLE);
progressBarTwo.setVisibility(v.VISIBLE);
} else if(i< 100) {
progressBarOne.setProgress(i);
progressBarOne.setSecondaryProgress(i + 10);
progressBarTwo.setProgress(i);
} else {
progressBarOne.setVisibility(v.GONE);
progressBarTwo.setVisibility(v.GONE);
i = -10;
}
i = i + 10;
}
}
}