android中的progressbar,ProgressBar使用详解
ProgressBar是Android下的进度条,也是为数不多的直接继承于View类的控件,直接子类有AbsSeekBar和ContentLoadingProgressBar,其中AbsSeekBar的子类有SeekBar和RatingBar
ProgressBar的使用注意:
1、ProgressBar有两个进度,一个是android:progress,另一个是android:secondaryProgress。后者主要是为缓存需要所涉及的,比如在看网络视频时候都会有一个缓存的进度条以及还要一个播放的进度,在这里缓存的进度就可以是android:secondaryProgress,而播放进度就是android:progress。
2、ProgressBar分为确定的和不确定的,上面说的播放进度、缓存等就是确定的。相反地,不确定的就是不清楚、不确定一个操作需要多长时间来完成,这个时候就需要用的不确定的ProgressBar了。这个是由属性android:indeterminate来控制的,如果设置为true的话,那么ProgressBar就可能是圆形的滚动条或者水平的滚动条(由样式决定)。默认情况下,如果是水平进度条,那么就是确定的。
3、ProgressBar的样式设定其实有两种方式,在API文档中说明的方式如下:
Widget.ProgressBar.Horizontal
Widget.ProgressBar.Small
Widget.ProgressBar.Large
Widget.ProgressBar.Inverse
Widget.ProgressBar.Small.Inverse
Widget.ProgressBar.Large.Inverse
使用的时候可以这样:style="@android:style/Widget.ProgressBar.Small"。另外还有一种方式就是使用系统的attr,上面的方式是系统的style:
style="?android:attr/progressBarStyle"
style="?android:attr/progressBarStyleHorizontal"
style="?android:attr/progressBarStyleInverse"
style="?android:attr/progressBarStyleLarge"
style="?android:attr/progressBarStyleLargeInverse"
style="?android:attr/progressBarStyleSmall"
style="?android:attr/progressBarStyleSmallInverse"
style="?android:attr/progressBarStyleSmallTitle"
ProgressBar几种比较常用的属性:
布局中设置:
android:progress="50"——第一显示进度
android:secondaryProgress="80"——第二显示进度
android:indeterminate="true"——设置是否精确显示,true表示不精确显示进度,false表示精确显示进度
使用Java代码设置:
setProgress(int) //设置第一进度
setSecondaryProgress(int) //设置第二进度
getProgress() //获取第一进度
getSecondaryProgress() //获取第二进度
incrementProgressBy(int) //增加或减少第一进度
incrementSecondaryProgressBy(int) //增加或减少第二进度
getMax() //获取最大进度
ProgressBar常见的几种样式
横向progressBarStyleHorizontal
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:max="100"
android:progress="50" />
效果图:
image.png
横向Widget.ProgressBar.Horizontal
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:max="100"
android:progress="50" />
效果图:
image.png
圆形:progressBarStyleLarge
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
效果图:
image.png
圆形:普通
android:layout_marginTop="10dp"
android:id="@+id/progressBar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
效果图:
image.png
圆形:progressBarStyleSmall
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal"
android:id="@+id/progressBar3"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
效果图:
image.png
自定义进度条修改进度的颜色
在布局文件中的style属性就是设置进度条样式的
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
实际上面的背景文件是位于@android:style/Widget.ProgressBar.Horizontal,既上面的布局可以写成
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
查看系统中的水平进度条风格文件
false
@drawable/progress_horizontal
@drawable/progress_indeterminate_horizontal
20dip
20dip
true
上面的android:progressDrawable属性是设置进度条背景,进入查看
android:startColor="#ff9d9e9d"
android:centerColor="#ff5a5d5a"
android:centerY="0.75"
android:endColor="#ff747674"
android:angle="270"
/>
android:startColor="#80ffd300"
android:centerColor="#80ffb600"
android:centerY="0.75"
android:endColor="#a0ffcb00"
android:angle="270"
/>
android:startColor="#ffffd300"
android:centerColor="#ffffb600"
android:centerY="0.75"
android:endColor="#ffffcb00"
android:angle="270"
/>
可以看到,上面文件中的3个item标签分别是设置:进度条、第二进度条、第一进度条的背景色。这里我们在drawable文件夹下新建一个pb_pd_sp_blog.xml文件,将上面的代码复制进来,并修改背景色。
android:startColor="#ff9d9e9d"
android:centerColor="#ff5a5d5a"
android:centerY="0.75"
android:endColor="#ff747674"
android:angle="270"
/>
android:startColor="#b9a4ff"
android:centerColor="#c6b7ff"
android:centerY="0.75"
android:endColor="#c3b2ff"
android:angle="270"
/>
android:startColor="#57e8ff"
android:centerColor="#74ebff"
android:centerY="0.75"
android:endColor="#8eefff"
android:angle="270"
/>
image.png
自定义进度条多种属性
我们不但可以修改进度的颜色,也可以修改其他属性我们可以自定义实现如下效果
布局中的属性设置
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:max="100"
android:progress="100"
android:maxHeight="12dp"
android:minHeight="12dp"
android:progressDrawable="@drawable/pb_pd_sp_download" />
drawable文件夹下的pb_pd_sp_downloadxml定义
android:color="@color/c_ffffff"
/>
android:height="12dp"
/>
android:width="2dp"
android:color="@color/c_c4e9ff"
/>
android:startColor="#b9a4ff"
android:centerColor="#c6b7ff"
android:centerY="0.75"
android:endColor="#c3b2ff"
android:angle="270"
/>
android:height="12dp"
/>
android:startColor="@color/c_5cacff"
android:centerColor="@color/c_0061dd"
android:endColor="@color/c_0061dd"
android:angle="45"
/>
android:height="12dp"
/>
android:width="2dp"
android:color="@android:color/transparent"
/>
效果图:
image.png
android中的progressbar,ProgressBar使用详解相关推荐
- Android中measure过程、WRAP_CONTENT详解以及xml布局文件解析流程浅析(下)
本文原创, 转载请注明出处:http://blog.csdn.net/qinjuning 上篇文章<<Android中measure过程.WRAP_CONTENT详解以及xml布局文 ...
- android 中的悬浮按钮,Android 中FloatingActionButton(悬浮按钮)实例详解
android 中floatingactionbutton(悬浮按钮)实例详解 一.介绍 这个类是继承自imageview的,所以对于这个控件我们可以使用imageview的所有属性 二.使用准备, ...
- Android中联系人和通话记录详解(2)
在文章Android中联系人和通话记录详解(1)中对通话记录进行了分析,本章将对联系人的数据库表.字段以及Insert,Query,Delelte,Update四大基本数据操作进行分析. 与联系人相关 ...
- Android中measure过程、WRAP_CONTENT详解以及 xml布局文件解析流程浅析
转自:http://www.uml.org.cn/mobiledev/201211221.asp 今天,我着重讲解下如下三个内容: measure过程 WRAP_CONTENT.MATCH_PAREN ...
- Android中内存泄漏超级精炼详解
一.前期基础知识储备 (1)什么是内存? JAVA是在JVM所虚拟出的内存环境中运行的,JVM的内存可分为三个区:堆(heap).栈(stack)和方法区(method). 栈(stack):是简单的 ...
- Android中measure过程、WRAP_CONTENT详解以及xml布局文件解析流程浅析(上)
在之前一篇博文中<< Android中View绘制流程以及invalidate()等相关方法分析>> ,简单的阐述 了 Android View 绘制流程的三个步骤,即: 1. ...
- android中几种定位方式详解
目录 前言: 1.GPS定位 2.NETWORK定位 3.AGPS定位 4.基站定位 5.WIFI定位 6.混合定位 目前,移动端大致通过三种方式来进行设备定位:GPS.基站.wifi.本文就详细的讲 ...
- android文件下载功能实现,Android中DownloadManager实现文件下载实例详解
Android中DownloadManager实现文件下载 下载 创建下载链接 DownloadManager.Request request = new DownloadManager.Reques ...
- Android中的单例模式(java单例模式详解,Glide,EventBus,LayoutInfalter的源码单例模式详解)
一.单例模式 (1)单例模式介绍和定义 大概意思是保证一个类在任何时候都只有一个实例在内存里,以static形式提供整个项目的访问.在Android系统中常用的地方有:创建一个SQLiteOpen ...
- Android 中 Scheme 协议的使用详解
什么是 URL Scheme? 简单的说就是 android 中的一种页面内跳转协议,方便 app 页面的内的跳转 2.什么时候使用 服务器下发跳转路径,客户端根据 服务器下发跳转路径跳转相应的页面 ...
最新文章
- emptyDir、hostPath以及local volume的不同
- 【金融】银行有什么分类
- 1959: 图案打印
- 马鞍山红星中学2021年高考成绩查询,2021年马鞍山高考状元名单公布,马鞍山高考状元学校资料及最高分...
- 95-134-110-源码-维表-Flink 1.9.0 维表实现
- sql 读取本地txt文件批量插入数据库
- java连接DB2数据库
- 使用application对象实现网站访问量统计
- 微信小程序getLocation定位偏差问题
- HDU 6232 Confliction
- 7-3 统计学生成绩 (15 分)
- CutefishOS 0.6 Beta 发布
- iOS之深入探究动画渲染降帧
- MATLAB颜色识别
- GIT创建仓库及导入源码小记
- 【ARM-Linux开发】【QT开发】Couldnt load module input, no modules loaded
- JMP的脚本JSL基础操作
- python前面三个大于号是啥_在Python3里有的变量前面有个*号,是什么意思?
- 痞子衡嵌入式:ARM Cortex-M文件那些事(6)- 可执行文件(.out/.elf)
- Tomcat启动报错 More than one fragment with the name [spring_web] was found. This is not legal with relat
热门文章
- 计算机科学与技术精品课程网,【计算机科学与技术专业】【毕业设计】《多媒体技术》精品课程平台的设计与实现...
- unity录音获取真实音频大小并获取字节流保存录音文件
- 【重识云原生】第二章计算第一节——计算虚拟化技术总述
- 第七十六章 方法关键字 - SoapAction
- Openwrt虚拟WAN口叠加网速
- LDA求解:Gibbs采样算法
- 数据分组合并有妙招!看如何处理同类项
- 使用TOMCAT+Mysql税控服务器访问时提示HTTP Status 404 - /SKServer/
- gihosoft tubeget为什么不能解析YouTube视频呢
- vs里 .sln .suo .ncb等后缀名详解