PregressBar可以用来设置进度,可以设置为圆圈形或者条形,案例图如下
<?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" >
<!-- 设置控件样式 -->
<ProgressBar
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:progress="30"
/>
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:secondaryProgress="60"
android:layout_marginTop="40dip"
android:progress="30"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/btn_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="增加"
/>
<Button
android:id="@+id/btn_cutback"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="减少"
/>
</LinearLayout>
</LinearLayout>
activity代码
package progress.bar;
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 implements OnClickListener {
private Button btn_add;
private Button btn_cutback;
private ProgressBar progress;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn_add=(Button)findViewById(R.id.btn_add);
btn_cutback=(Button)findViewById(R.id.btn_cutback);
progress=(ProgressBar)findViewById(R.id.progress);
btn_add.setOnClickListener(this);
btn_cutback.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.btn_add:
//拿到当前进度
int currentProgress= progress.getProgress();
int prog = (int)( currentProgress*1.2);
progress.setProgress(prog);
break;
case R.id.btn_cutback:
//拿到当前进度
int currentProgress2= progress.getProgress();
int prog2 = (int)( currentProgress2*0.8);
progress.setProgress(prog2);
}
}
}