ProgressBar学习笔记,自定义横向进度条的样式(包含ActionBar上面的进度条)
 点显示进度条后→  
 android:max="100"         进度条的最大值
        android:progress            进度条已经完成的进度值
    	android:progressDrawable     		已经完成的进度条轨道显示的Drawable对象
indeterminateDrawable       设置绘制不显示进度的进度条的Drawable对象
        android:indeterminate       			设置为true,进度条不精准显示进度
        android:indeterminateDuration   设置不精准显示进度的时间
布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="大环形进度条"
android:textAppearance="?android:attr/textAppearanceMedium" /> <ProgressBar
android:id="@+id/progressBar01_id"
style="?android:attr/progressBarStyleLarge"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="普通的进度条"
android:textAppearance="?android:attr/textAppearanceMedium" /> <ProgressBar
android:id="@+id/progressBar02_id"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="小的环形进度条"
android:textAppearance="?android:attr/textAppearanceMedium" /> <ProgressBar
android:id="@+id/progressBar03_id"
android:layout_gravity="center_horizontal"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="横向水平的进度条"
android:textAppearance="?android:attr/textAppearanceMedium" /> <ProgressBar
android:id="@+id/progressBar04_id"
style="?android:attr/progressBarStyleHorizontal"
android:max="100"
android:progressDrawable="@drawable/bar_color"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="水平进度条(自定义外观)"
android:layout_marginTop="10dp"
android:textAppearance="?android:attr/textAppearanceMedium" /> <ProgressBar
android:id="@+id/progressBar05_id"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="40"
android:progressDrawable="@drawable/bar_style" /> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"> <Button
android:id="@+id/show_button_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="显示进度条" /> <Button
android:id="@+id/hint_button_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="隐藏进度条" /> </LinearLayout> </LinearLayout>
bar_color.xml 设置进度条的颜色
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 设置背景色(蓝色) -->
<item android:id="@android:id/background" >
<shape>
<corners android:radius="6dp" />
<gradient android:startColor="#0000ff"
android:endColor="#0000ff" />
</shape>
</item> <!-- 设置进度条颜色(红色) -->
<item android:id="@android:id/progress" >
<clip>
<shape>
<corners android:radius="6dp" />
<gradient android:startColor="#ff0000"
android:endColor="#ff0000" />
</shape>
</clip>
</item> </layer-list>
bar_style.xml 用图片来设置进度条
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 设置背景色图像资源 -->
<item
android:id="@android:id/background"
android:drawable="@drawable/bar_bg" /> <!-- 设置进度条颜色图像资源 -->
<item
android:id="@android:id/progress"
android:drawable="@drawable/bar_progress" /> </layer-list>
MainActivity.java
package com.kale.progressbar; import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ProgressBar; public class MainActivity extends Activity { ProgressBar pB04,pB05;
Button showBt,hintBt;
//模拟一个长度为100的数组
private int [] data = new int[100];
int hasData = 0,status = 0;
Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
if(msg.what == 0x111) {
pB04.setProgress(status);
pB05.setProgress(status);
}
}
}; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_PROGRESS);//在窗口标题上显示带进度的横向进度条
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);//显示不带进度的进度条 //上面的代码必须在setContentView之前写
setContentView(R.layout.activity_main);
initView();
new Thread() {
public void run() {
while(status < 100) {
//获取耗时操作完成的百分比
status = doWork();
//发送消息
mHandler.sendEmptyMessage(0x111);
}
}
}.start(); showBt.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
//显示不带进度的进度条
setProgressBarIndeterminate(true);
//显示带进度的进度条
setProgressBarVisibility(true);
setProgress(4500); }
}); hintBt.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
//隐藏不带进度的进度条
setProgressBarIndeterminate(false);
//隐藏带进度的进度条
setProgressBarVisibility(false);
}
});
} public int doWork() {
data[hasData++] = (int)(Math.random() * 100);
try {
Thread.sleep(100);
} catch (Exception e) {
// TODO: handle exception
}
return hasData;
} private void initView() {
pB04 = (ProgressBar)findViewById(R.id.progressBar04_id);
pB05 = (ProgressBar)findViewById(R.id.progressBar05_id);
showBt = (Button) findViewById(R.id.show_button_id);
hintBt = (Button)findViewById(R.id.hint_button_id);
}
}
源码地址:http://download.csdn.net/detail/shark0017/7650871
ProgressBar学习笔记,自定义横向进度条的样式(包含ActionBar上面的进度条)的更多相关文章
- iOS学习笔记-自定义过渡动画
		
代码地址如下:http://www.demodashi.com/demo/11678.html 这篇笔记翻译自raywenderlick网站的过渡动画的一篇文章,原文用的swift,由于考虑到swif ...
 - iOS 去掉tabaar上面的 一条线
		
iOS 去掉tabaar上面的 一条线 利用一个 1像素高的图片 [[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"tr ...
 - Dynamic CRM 2013学习笔记(二十五)JS调用web service 实现多条记录复制(克隆)功能
		
前面介绍过如何克隆一条当前的记录: Dynamic CRM 2013学习笔记(十四)复制/克隆记录 , 主要是通过界面上加一个字段,单击form上的clone 按钮时,改变这个字段的值以触发插件来实现 ...
 - Android学习笔记之横向二级菜单实现
		
PS:元旦来一发. 学习内容: 1.Android二级横向菜单的实现过程.效果如上图... 这种横向的二级菜单在很多的app都有所应用.效果看起来还是非常的美观的.也算是项目需要,自己也就学了一下 ...
 - Spark学习笔记3(IDEA编写scala代码并打包上传集群运行)
		
Spark学习笔记3 IDEA编写scala代码并打包上传集群运行 我们在IDEA上的maven项目已经搭建完成了,现在可以写一个简单的spark代码并且打成jar包 上传至集群,来检验一下我们的sp ...
 - 【Spring学习笔记-MVC-13.2】Spring MVC之多文件上传
		
作者:ssslinppp 1. 摘要 前篇文章讲解了单文件上传<[Spring学习笔记-MVC-13]Spring MVC之文件上传>http://www.cnblogs.co ...
 - 【转】Pro Android学习笔记(五):了解Content Provider(上)
		
Content Provider是抽象数据封装和数据访问机制,例如SQLite是Android设备带有的数据源,可以封装到一个content provider中.要通过content provider ...
 - 【转】Pro Android学习笔记(三):了解Android资源(上)
		
在Android开发中,资源包括文件或者值,它们和执行应用捆绑,无需在源代码中写死,因此我们可以改变或替换他们,而无需对应用重新编译. 了解资源构成 参考阅读Android学习笔记(三八):资源res ...
 - 【Android开发学习笔记】【第七课】五大布局-上
		
概念 Android程序各式各样,依靠的就是布局,先来看看布局都是怎么来的: 白色部分就是我们经常用的几种布局,主要说说介绍下面五大布局 FrameLayout AbsoluteLayout Line ...
 
随机推荐
- element-ui的rules中正则表达式
			
<template> <el-form :model="unuseForm" label-position="top" :rules=&quo ...
 - 深刻理解this的指向和var 定义的变量的问题
			
一般来说,在编程语言里我们常见的变量作用域就是词法作用域与动态作用域(Dynamic Scope),绝大部分的编程语言都是使用的词法作用域.词法作用域注重的是所谓的Write-Time,即编程时的上下 ...
 - 通俗讲解transform3D变换时css各属性的作用与搭配
			
当没有浏览器兼容性限制时,就大胆地使用transiton的3D效果吧,前端也要做不一样的烟火! *常用的3D效果 rotateX/rotateY/rotateZ/rotate3dtranslateX/ ...
 - 基于CommonsCollections4的Gadget分析
			
基于CommonsCollections4的Gadget分析 Author:Welkin 0x1 背景及概要 随着Java应用的推广和普及,Java安全问题越来越被人们重视,纵观近些年来的Java安全 ...
 - WEP自动破解工具wesside-ng
			
WEP自动破解工具wesside-ng wesside-ng是aircrack-ng套件提供的一个概念验证工具.该工具可以自动扫描无线网络,发现WEP加密的AP.然后,尝试关联该AP.关联成功后, ...
 - mysql的checkpoint
			
上一章的结尾我们留下了一个问题,就是在上一章所介绍的模型中,恢复管理器必须要通过全篇扫描整个undolog进行日志恢复,这样做显然是没有太大必要的,因为系统中断肯定是在最后几个事务受到影响,前面的事务 ...
 - 关于Android中传递数据的一些讨论
			
在Android中编写过程序的开发人员都知道.在Activity.Service等组件之间传递数据(尤其是复杂类型的数据)很不方便.一般可以使用Intent来传递可序列化或简单类型的数据.看下面的代码 ...
 - oracle直接读写ms sqlserver数据库(二)配置透明网关
			
环境说明: 数据库版本:11gR2 透明网关版本:11g 操作系统Windows Server2008_64位 ORACLE_HOME目录:D:\app\Administrator\product\1 ...
 - ZOJ 3765 Lights (伸展树splay)
			
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3765 Lights Time Limit: 8 Seconds ...
 - CoreSight™ Technology
			
ARM Cortex-M processor-based devices use the ARM CoreSight technology which introduces powerful new ...