ProgressBar的使用

本文详细介绍了Android中ProgressBar的基本用法,包括简单的样式应用、在标题栏和对话框中的使用方法,以及如何自定义进度条样式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值