ProgressBar
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
ProgressBar是Android系统中的一种UI组件,它用于向用户展示进度或加载状态,通常在执行耗时操作时使用,如文件下载、数据加载等。在Android开发中,ProgressBar分为两种主要类型:水平进度条(Horizontal ProgressBar)和圆形进度条(Circular ProgressBar)。本篇将深入解析ProgressBar的使用方法和自定义技巧。 我们来了解一下ProgressBar的基本用法。在XML布局文件中,可以通过以下方式添加一个水平进度条: ```xml <ProgressBar android:id="@+id/progressBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:max="100" /> ``` 其中,`android:max`属性定义了进度的最大值,默认为100。在代码中,你可以通过`setProgress(int progress)`方法设置当前进度,并使用`getProgress()`获取当前进度。 对于需要显示具体百分比的场景,可以使用`android:progressBackgroundTint`和`android:progressTint`属性来改变进度条的背景颜色和填充颜色,以提供视觉反馈。同时,`android:indeterminate`属性可开启不确定模式,此时进度条会以某种动画形式连续移动,表示任务正在进行但无法预估剩余时间。 对于更复杂的自定义需求,可以使用`android:indeterminateDrawable`和`android:progressDrawable`属性来自定义进度条的样式。例如,可以创建一个自定义的渐变色条纹动画: ```xml <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@android:id/background"> <shape> <solid android:color="#EDEDED"/> </shape> </item> <item android:id="@android:id/progress"> <clip> <shape> <solid android:color="@android:color/holo_blue_bright"/> </shape> </clip> </item> </layer-list> ``` 然后将这个drawable资源文件赋值给`android:progressDrawable`。 对于圆形进度条,可以使用`android:indeterminate`属性开启不确定模式,或者通过`android:progressBackgroundTint`和`android:progressTint`进行颜色定制。此外,`android:rotation`属性可以控制圆形进度条的旋转方向。 在编程过程中,往往需要动态更新进度条,这可以通过`AsyncTask`或`Handler`来实现。例如,在后台线程执行任务并更新进度: ```java new AsyncTask<Void, Integer, Void>() { @Override protected Void doInBackground(Void... voids) { for (int i = 0; i <= 100; i++) { publishProgress(i); } return null; } @Override protected void onProgressUpdate(Integer... values) { progressBar.setProgress(values[0]); } }.execute(); ``` 标签“源码”提示我们关注ProgressBar的内部实现。在Android开源项目中,我们可以查看ProgressBar的相关源代码,理解其内部的工作原理。例如,`ProgressBar`是如何处理进度更新,以及如何绘制进度条的。 ProgressBar是Android UI设计中不可或缺的一部分,它能够为用户提供实时的反馈信息,提升用户体验。通过学习和理解其使用方法和自定义技巧,开发者可以更好地满足各种应用场景的需求,创造出更具吸引力的界面。
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
- 1
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
- 粉丝: 386
- 资源: 6万+
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- Sigrity-SPEED2000-EMI Simulation Tutorial.rar
- pyhon 3.8.20 安装包
- Sigrity-SPEED2000-DDR Simulation Tutorial - SODIMM.rar
- pyhon 3.11.10 安装包
- 当前车速度大于3m/s跟随前车行驶,当前车速度小于3m/s,对前车绕行
- Sigrity-SPEED2000-DDR Simulation Tutorial - DIMMonBoard.rar
- pyhon 3.10.5 安装包
- Sigrity-SPEED2000 User’s Guide.rar
- Sigrity-SPEED2000 Getting Started Guide.rar
- vscode 1.93.0 中文语言插件
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)