ProgressBar的使用
1.简单使用
<ProgressBar
style="?android:attr/progressBarStyleHorizontal" //条状
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar" />
<ProgressBar
style="?android:attr/progressBarStyleLarge" //大圈
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar2" />
<ProgressBar //正常圈
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar3" />
<ProgressBar
style="?android:attr/progressBarStyleSmall" //小圈
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar4" />
2.标题栏上的进度条
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); //这句应在setContentView的前面
setContentView(R.layout.activity_main);
setProgressBarIndeterminateVisibility(true);
3.对话框进度条
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="对话框进度条"
android:onClick="showDialogProgress"/>
public void showDialogProgress(View v){
ProgressDialog pd = new ProgressDialog(this);
// 设置进度条的最大值
pd.setMax(150);
// 是否是确定的进度条
pd.setIndeterminate(false);
// 设置进度条的title
pd.setTitle("Title");
// 设置对话框的提示信息
pd.setMessage("waiting...");
// 设置进度条样式
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// 设置对话框是否可以被取消
pd.setCancelable(true);
pd.show();
// 设置进度条的进度,注意得放在show方法后面才行
pd.setProgress(100);
}
4.自定义进度条
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateDrawable="@drawable/progress_bg"/>
在drawable目录下新建resource file 并将根节点改为 layer-list
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<rotate
android:drawable="@mipmap/ba"
android:fromDegrees="0"
android:pivotX="50%" //转动的圆心
android:pivotY="50%"
android:toDegrees="360"></rotate>
</item>
</layer-list>
ProgressBar的使用
最新推荐文章于 2023-06-07 09:12:32 发布