Android控件之ProgressBar
1,带有进度条的ProgressBar
[html]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Request the progress bar to be shown in the title
requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.progressbar_1);
setProgressBarVisibility(true);//设置在title里的ProgressBar可见
final ProgressBar progressHorizontal = (ProgressBar) findViewById(R.id.progress_horizontal);
setProgress(progressHorizontal.getProgress() * 100);//为title中的ProgressBar设置进度
setSecondaryProgress(progressHorizontal.getSecondaryProgress() * 100);//为title中的ProgressBar设置二级进度
Button button = (Button) findViewById(R.id.increase);//一级进度递增
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
progressHorizontal.incrementProgressBy(1);
// Title progress is in range 0..10000
setProgress(100 * progressHorizontal.getProgress());//为title中的ProgressBar设置进度
}
});
button = (Button) findViewById(R.id.decrease);//一级进度递减
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
progressHorizontal.incrementProgressBy(-1);
// Title progress is in range 0..10000
setProgress(100 * progressHorizontal.getProgress());//为title中的ProgressBar设置进度
}
});
button = (Button) findViewById(R.id.increase_secondary);//二级进度递增
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
progressHorizontal.incrementSecondaryProgressBy(1);
// Title progress is in range 0..10000
setSecondaryProgress(100 * progressHorizontal.getSecondaryProgress());
}
});
button = (Button) findViewById(R.id.decrease_secondary);//二级进度递减
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
progressHorizontal.incrementSecondaryProgressBy(-1);
// Title progress is in range 0..10000
setSecondaryProgress(100 * progressHorizontal.getSecondaryProgress());
}
});
}
配置文件 :
[html]
<ProgressBar android:id="@+id/progress_horizontal"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:max="100"
android:progress="50"
android:secondaryProgress="75" />
效果图:
2, 转圈的样式的ProgressBar
[html]
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ProgressBar
android:id="@+android:id/progress_large"
style="?android:attr/progressBarStyleLarge"//大样式
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ProgressBar //默认
android:id="@+android:id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ProgressBar
android:id="@+android:id/progress_small" //小样式
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ProgressBar //小标题样式
android:id="@+android:id/progress_small_title"
style="?android:attr/progressBarStyleSmallTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Java代码:
[html]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Request for the progress bar to be shown in the title
requestWindowFeature(Window.FEATURE_<span style="color:#ff0000;">INDETERMINATE</span>_PROGRESS);
&nbs
补充:移动开发 , Android ,