[ 转] [Android]多式样ProgressBar
多式样ProgressBar
普通圆形ProgressBar


该类型进度条也就是一个表示运转的过程,例如发送短信,连接网络等等,表示一个过程正在执行中。
一般只要在XML布局中定义就可以了。
- <progressBar android:id="@+id/widget43"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical">
- </ProgressBar>
复制代码
此时,没有设置它的风格,那么它就是圆形的,一直会旋转的进度条。
各大小样式圆形ProgressBar
超大号圆形ProgressBar
此时,给设置一个style风格属性后,该ProgressBar就有了一个风格,这里大号ProgressBar的风格是:
- style="?android:attr/progressBarStyleLarge"
复制代码
完整XML定义是:
- <progressBar android:id="@+id/widget196"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- style="?android:attr/progressBarStyleLarge">
- </ProgressBar>
复制代码
小号圆形ProgressBar

小号ProgressBar对应的风格是:
- style="?android:attr/progressBarStyleSmall"
复制代码
完整XML定义是:
- <progressBar android:id="@+id/widget108"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- style="?android:attr/progressBarStyleSmall">
- </ProgressBar>
复制代码
标题型圆形ProgressBar


标题型ProgressBar对应的风格是:
- style="?android:attr/progressBarStyleSmallTitle"
复制代码
完整XML定义是:
- <progressBar android:id="@+id/widget110"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- style="?android:attr/progressBarStyleSmallTitle">
- </ProgressBar>
复制代码
代码中实现:
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
- //请求窗口特色风格,这里设置成不明确的进度风格
- setContentView(R.layout.second);
- setProgressBarIndeterminateVisibility(true);
- //设置标题栏中的不明确的进度条是否可以显示
- }
复制代码
长形进度条
布局中的长形进度条
①首先在XML进行布局
- <progressBar android:id="@+id/progressbar_updown"
- android:layout_width="200dp"
- android:layout_height="wrap_content"
- style="?android:attr/progressBarStyleHorizontal"
- android:layout_gravity="center_vertical"
- android:max="100"
- android:progress="50"
- android:secondaryProgress="70" >
复制代码
讲解:
| style="?android:attr/progressBarStyleHorizontal" | 设置风格为长形 |
| android:max="100" | 最大进度值为100 |
| android:progress="50" | 初始化的进度值 |
| android:secondaryProgress="70" | 初始化的底层第二个进度值 |
| android:layout_gravity="center_vertical" | 垂直居中 |
②代码中运用
- private ProgressBar myProgressBar;
- //定义ProgressBar
- myProgressBar = (ProgressBar) findViewById(R.id.progressbar_updown);
- //ProgressBar通过ID来从XML中获取
- myProgressBar.incrementProgressBy(5);
- //ProgressBar进度值增加5
- myProgressBar.incrementProgressBy(-5);
- //ProgressBar进度值减少5
- myProgressBar.incrementSecondaryProgressBy(5);
- //ProgressBar背后的第二个进度条 进度值增加5
- myProgressBar.incrementSecondaryProgressBy(-5);
- //ProgressBar背后的第二个进度条 进度值减少5
复制代码
页面标题中的长形进度条
代码实现:
①先设置一下窗口风格特性
- requestWindowFeature(Window.FEATURE_PROGRESS);
- //请求一个窗口进度条特性风格
- setContentView(R.layout.main);
- setProgressBarVisibility(true);
- //设置进度条可视
复制代码
②然后设置进度值
- setProgress(myProgressBar.getProgress() * 100);
- //设置标题栏中前景的一个进度条进度值
- setSecondaryProgress(myProgressBar.getSecondaryProgress() * 100);
- //设置标题栏中后面的一个进度条进度值
- //ProgressBar.getSecondaryProgress() 是用来获取其他进度条的进度值
复制代码
ProgressDialog
ProgressDialog中的圆形进度条
ProgressDialog一般用来表示一个系统任务或是开启任务时候的进度,有一种稍等的意思。
代码实现:
- ProgressDialog mypDialog=new ProgressDialog(this);
- //实例化
- mypDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
- //设置进度条风格,风格为圆形,旋转的
- mypDialog.setTitle("Google");
- //设置ProgressDialog 标题
- mypDialog.setMessage(getResources().getString(R.string.second));
- //设置ProgressDialog 提示信息
- mypDialog.setIcon(R.drawable.android);
- //设置ProgressDialog 标题图标
- mypDialog.setButton("Google",this);
- //设置ProgressDialog 的一个Button
- mypDialog.setIndeterminate(false);
- //设置ProgressDialog 的进度条是否不明确
- mypDialog.setCancelable(true);
- //设置ProgressDialog 是否可以按退回按键取消
- mypDialog.show();
- //让ProgressDialog显示
复制代码
ProgressDialog中的长形进度条

代码实现:
- ProgressDialog mypDialog=new ProgressDialog(this);
- //实例化
- mypDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
- //设置进度条风格,风格为长形,有刻度的
- mypDialog.setTitle("地狱怒兽");
- //设置ProgressDialog 标题
- mypDialog.setMessage(getResources().getString(R.string.second));
- //设置ProgressDialog 提示信息
- mypDialog.setIcon(R.drawable.android);
- //设置ProgressDialog 标题图标
- mypDialog.setProgress(59);
- //设置ProgressDialog 进度条进度
- mypDialog.setButton("地狱曙光",this);
- //设置ProgressDialog 的一个Button
- mypDialog.setIndeterminate(false);
- //设置ProgressDialog 的进度条是否不明确
- mypDialog.setCancelable(true);
- //设置ProgressDialog 是否可以按退回按键取消
- mypDialog.show();
- //让ProgressDialog显示
复制代码
AlertDialog.Builder
AlertDialog中的圆形ProgressBar
①先来设计一个Layout,待会儿作为一个View,加入AlertDialog.Builder
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_gravity="center_horizontal"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <LinearLayout android:id="@+id/LinearLayout01"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- </LinearLayout>
- <ProgressBar android:layout_gravity="center_vertical|center_horizontal"
- android:layout_height="wrap_content"
- android:progress="57"
- android:id="@+id/myView_ProgressBar2"
- android:layout_width="wrap_content">
- </ProgressBar>
- </LinearLayout>
复制代码
②代码罗
- private AlertDialog.Builder AlterD,AlterD2;
- //定义提示对话框
- private LayoutInflater layoutInflater;
- //定义布局过滤器
- private LinearLayout myLayout;
- //定义布局
- layoutInflater2=(LayoutInflater) getSystemService(this.LAYOUT_INFLATER_SERVICE);
- //获得系统的布局过滤服务
- myLayout2=(LinearLayout) layoutInflater2.inflate(R.layout.roundprogress, null);
- //得到事先设计好的布局
- AlterD2.setTitle(getResources().getString(R.string.RoundO));
- //设置对话框标题
- AlterD2.setIcon(R.drawable.ma);
- //设置对话框图标
- AlterD2.setMessage(getResources().getString(R.string.ADDView));
- //设置对话框提示信息
- AlterD2.setView(myLayout2);
- //设置对话框中的View
- AlterD2.show();
- //让对话框显示
复制代码
AlertDialog中的长形ProgressBar(可控制)
①先来设计一个Layout,待会儿作为一个View,加入AlertDialog.Builder
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_gravity="center_horizontal"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <Button
- android:layout_height="wra
源地址:http://blog.renren.com/share/280454800/6285354069
另外可参见:http://blog.csdn.net/mad1989/article/details/38042875
[ 转] [Android]多式样ProgressBar的更多相关文章
- Android学习笔记——ProgressBar
该工程的功能是实现进度条的显示,按以下按钮进度条增加10% 以下代码是MainActivity.java中的代码 package com.example.progressbar; import and ...
- Android学习之ProgressBar
ProgressBar用于向用户显示某个耗时操作完成的百分比,避免长时间执行某个耗时操作时让用户感觉程序失去了响应,从而提高用户界面的友好性. 请看下面的界面布局: <LinearLayout ...
- Android——进度条ProgressBar
1.activity_progressbar.xml <?xml version="1.0" encoding="utf-8"?><Linea ...
- Android学习笔记- ProgressBar(进度条)
本节引言: 本节给大家带来的是Android基本UI控件中的ProgressBar(进度条),ProgressBar的应用场景很多,比如 用户登录时,后台在发请求,以及等待服务器返回信息,这个时候会用 ...
- Android笔记(二十三) Android中的ProgressBar(进度条)
圆形进度条和水平进度条 进度条也是UI界面一种非常实用的组件,通常用于向用户显示某个耗时操作完成的百分比,进度条可以动态的显示进度,避免长时间的执行某个耗时操作时,让用户感觉程序失去了相应,从而更好的 ...
- android 代码设置progressBar 颜色
void test() { LinearLayout linearLayout = new LinearLayout(this); ProgressBar progressBar = new Prog ...
- Android中自定义ProgressBar
<ProgressBar android:id="@+id/more_vprogress_more" android:layo ...
- Android成长日记-ProgressBar的设计
ProgressBar的关键属性 Android:max=”100” - ---最大显示进度 Android:progress=”50”----第一显示进度 Android:secondaryProg ...
- Android自定义圆形ProgressBar
闲来无事做了一个自定义的进度条,大致效果图如下: progressbar.gif 废话不多说,下面直接上代码: 自定义控件代码CircleProgressBar.java: public class ...
随机推荐
- 黑客攻防技术宝典Web实战篇(三)web攻击方式总结
web攻击的手段无非就是使服务器资源耗尽,使服务器无法接收正常请求. 一.DDos攻击 二.DRDos攻击 三.慢攻击 与Ddos攻击相反,慢攻击并不是以多取胜,而是靠保持连接.
- web 开发前端学习
调试插件:http://www.getpostman.com/ http://bootstrap.evget.com/javascript.html bootstrap: http://www.bo ...
- JavaWeb学习总结(五十一)——邮件的发送与接收原理
一. 邮件开发涉及到的一些基本概念 1.1.邮件服务器和电子邮箱 要在Internet上提供电子邮件功能,必须有专门的电子邮件服务器.例如现在Internet很多提供邮件服务的厂商:sina.sohu ...
- 3_mysql 主从复制
mysql 主从复制 网易数据库 石勇 提纲 什么是主从复制 主从复制的原理 主从复制的用途 主从复制的搭建 主从复制的问题 什么是主从复制 数据拷贝 准实时 源-主节点:目的-从节点 主从复制的原理 ...
- PHP拦截器之__set()与__get()的理解与使用
“一般来说,总是把类的属性定义为private,这更符合现实的逻辑.但是,对属性的读取和赋值操作是非常频繁的,因此在PHP5中,预定义了两个函数“__get()”和“__set()”来获取和赋值其属性 ...
- Code First04---关于上下文DbContext
这章主要讲怎么配置DbContext的子类访问的数据库的位置. 我相信大家最经常使用的数据库位置的配置方式就是配置文件了,也就是通过App.Config 或Web.Config来配置要访问的数据库. ...
- jQuery对话框插件 ThickBox
http://baike.haosou.com/doc/7607201-7881296.html 项目已经停止维护,但该插件还是不错的! ThickBox是一个基于JQuery类库的扩展,它能在浏览器 ...
- 弹窗插件 popup.js 完美修正版
作为信息展示弹出窗口,很有用!是一个js插件,不是jQuery插件! 地址:http://img.jb51.net/online/popup/popup.html
- DOM之节点层次
1.1 Node类型 DOM1级定义了一个Node接口,该接口将由DOM中的所有节点类型实现.这个Node接口在JS中是作为Node类型实现的:除了IE之外,其他浏览器可访问这个类型.JS中的所有节点 ...
- HDU 5053 the Sum of Cube
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5053 解题报告:用来陶冶情操的题,求a到b的三次方的和. #include<stdio.h> ...