首先是main.xml文件

代码如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ProgressBar
android:id="@+id/myprobarA"
style="?android:attr/progressBarStyle"
android:visibility="gone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ProgressBar
android:id="@+id/myprobarB"
style="?android:attr/progressBarStyleHorizontal"
android:visibility="gone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ProgressBar
android:id="@+id/myprobarC"
style="?android:attr/progressBarStyleHorizontal"
android:visibility="gone"
android:max="120"
android:progress="0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ProgressBar
android:id="@+id/myprobarD"
android:visibility="gone"
android:max="120"
android:progress="50"
android:secondaryProgress="70"
style="?android:attr/progressBarStyleLarge"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ProgressBar
android:id="@+id/myprobarE"
android:visibility="gone"
android:max="120"
android:progress="50"
android:secondaryProgress="70"
style="?android:attr/progressBarStyleSmall"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/mybut"
android:text="显示进度条"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

  然后编写Activity.java类

代码如下:

package com.example.myfirstproject;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.*; public class MainActivity extends Activity {
private ProgressBar myprobarA,myprobarB,myprobarC,myprobarD,myprobarE;
private Button mybut;
protected static final int STOP = 1;
protected static final int CONTINUE = 2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.myprobarA = (ProgressBar)this.findViewById(R.id.myprobarA);
this.myprobarB = (ProgressBar)this.findViewById(R.id.myprobarB);
this.myprobarC = (ProgressBar)this.findViewById(R.id.myprobarC);
this.myprobarD = (ProgressBar)this.findViewById(R.id.myprobarD);
this.myprobarE = (ProgressBar)this.findViewById(R.id.myprobarE);
this.mybut = (Button)this.findViewById(R.id.mybut);
this.myprobarA.setIndeterminate(false);
this.myprobarB.setIndeterminate(false);
this.myprobarC.setIndeterminate(true);
this.myprobarD.setIndeterminate(false);
this.myprobarE.setIndeterminate(false);
this.mybut.setOnClickListener(new OnClickListenerlmpl());
}
private class OnClickListenerlmpl implements OnClickListener{
public void onClick(View view){
MainActivity.this.myprobarB.setSecondaryProgress(0);
MainActivity.this.myprobarA.setVisibility(View.VISIBLE);
MainActivity.this.myprobarB.setVisibility(View.VISIBLE);
MainActivity.this.myprobarC.setVisibility(View.VISIBLE);
MainActivity.this.myprobarD.setVisibility(View.VISIBLE);
MainActivity.this.myprobarE.setVisibility(View.VISIBLE);
MainActivity.this.myprobarA.setMax(120);
MainActivity.this.myprobarB.setMax(120);
MainActivity.this.myprobarA.setProgress(0);
MainActivity.this.myprobarB.setProgress(0);
new Thread(new Runnable(){
public void run(){
int count = 0;
for(int i = 0;i < 10;i++){
try{
count = (i+1)*20;
Thread.sleep(500);
if(i==6){
Message m = new Message();
m.what = MainActivity.STOP;
MainActivity.this.myMessageHandler.sendMessage(m);
break;
}else{
Message m = new Message();
m.arg1 = count;
m.what = MainActivity.CONTINUE;
MainActivity.this.myMessageHandler.sendMessage(m);
}
}catch(Exception ex){
ex.printStackTrace();
}
}
}
}).start();
}
}
private Handler myMessageHandler = new Handler(){
public void handleMessage(Message msg){
switch(msg.what){
case MainActivity.STOP:
myprobarA.setVisibility(View.GONE);
myprobarB.setVisibility(View.GONE);
myprobarC.setVisibility(View.GONE);
myprobarD.setVisibility(View.GONE);
myprobarE.setVisibility(View.GONE);
Thread.currentThread().interrupt();
break;
case MainActivity.CONTINUE:
if(!Thread.currentThread().isInterrupted()){
myprobarA.setProgress(msg.arg1);
myprobarB.setProgress(msg.arg1);
myprobarC.setProgress(msg.arg1);
myprobarD.setProgress(msg.arg1);
myprobarE.setProgress(msg.arg1);
}
break;
}
}
};
}

  运行效果:

android之进度条组件ProgressBar的更多相关文章

  1. Android学习笔记(24):进度条组件ProgressBar及其子类

    ProgressBar作为进度条组件使用,它还派生了SeekBar(拖动条)和RatingBar(星级评分条). ProgressBar支持的XML属性: Attribute Name Related ...

  2. 【Android 应用开发】 自定义 圆形进度条 组件

    转载著名出处 : http://blog.csdn.net/shulianghan/article/details/40351487 代码下载 : -- CSDN 下载地址 : http://down ...

  3. progressbar进度条组件

    Progressbar 进度条组件 通过$.fn.progressbar.fn.defaults重写默认的defaults进度条(progressbar)提供了一种显示长时间操作进度的反馈.进度可被更 ...

  4. 第一百九十八节,jQuery EasyUI,ProgressBar(进度条)组件

    jQuery EasyUI,ProgressBar(进度条)组件 学习要点: 1.加载方式 2.属性列表 3.事件列表 4.方法列表 本节课重点了解 EasyUI 中 ProgressBar(进度条) ...

  5. 详解Bootstrap进度条组件

    在网页中,进度条的效果并不少见,如:平分系统.加载状态等,进度条组件使用了css3的transition和animation属性来完成一些特效,这些特效在IE9及IE9以下版本.Firefox的老版本 ...

  6. Android 设置进度条背景

    Android 设置进度条背景 直接上代码 <ProgressBar android:id="@+id/progressBar" android:layout_width=& ...

  7. android 自定义进度条颜色

    android 自定义进度条颜色 先看图 基于产品经理各种自定义需求,经过查阅了解,下面是自己对Android自定义进度条的学习过程!   这个没法了只能看源码了,还好下载了源码, sources\b ...

  8. Android之进度条2

    我之前有写过一篇“Android之进度条1”,那个是条形的进度条(显示数字进度),这次实现圆形进度条. 点击查看Android之进度条1:http://www.cnblogs.com/caidupin ...

  9. android的进度条使用

    android的进度条 1.实现的效果 2.布局代码 先写一个my_browser.xml文件 存放WebView <?xml version="1.0" encoding= ...

随机推荐

  1. 【前台页面 BUG】回车按钮后,页面自动跳转

    点击回车按钮后,页面自动的迅速跳转 原因: 表单隐式提交了. 解决方法: 在方法执行完成后,加上return false; 代码如下: /** * 注册按钮的点击事件 */ $("#regi ...

  2. URL编码表%20Base64编码表%20HTTP消息含义

    URL编码表 backspace 8% A 41% a 61% § %A7 Õ %D5   tab 9% B 42% b 62% « %AB Ö %D6   linefeed %0A C 43% c ...

  3. MIT 6.828 JOS学习笔记1. Lab 1 Part 1: PC Bootstrap

    Lab 1: Booting a PC Part 1: PC Bootstrap 介绍这一部分知识的目的就是让你能够更加熟悉x86汇编语言,以及PC启动的整个过程,而且也会首次学习使用QEMU软件来仿 ...

  4. JMeter性能监测插件介绍(三)

    JMeter 性能监测插件介绍 压力测试过程中,能够随时对负载服务器的健康状况的把控是相当重要的,有了这些数据,我们才能准确分析出服务器负载瓶颈.JMeter 插件包现在能够支持服务器监控,可以在所有 ...

  5. @import与link

    本质上,这两种方式都是为了加载CSS文件,但还是存在着细微的差别. 1. 老祖宗的差别.link属于XHTML标签,而@import完全是CSS提供的一种方式. link标签除了可以加载CSS外,还可 ...

  6. shell-bash学习04读取输入、分隔符、流程控制

    读入输出 输入通常是通过stdin或参数传递给命令; 输出出现在stderr或stdout; 管道,过滤器,管道操作符: cmd1 | cmd2 | cmd3; //最后还有输出 ls | cat - ...

  7. ember.js:使用笔记1-数组数据统一显示

    ember中数据一般都是以array的形式存储的,控制器使用,如: App.DataController = Em.ArrayController.extend({}); 想要在一个页面中输出所有的数 ...

  8. JS原型对象通俗"唱法"

    书上对于原型对象的说法给我整的眼花缭乱,完全不知道它在说什么,查了好多资料,终于有了些理解,下面我以通俗的大白话说说我对原型对象的理解. 1.关于原型对象的重要知识点 首先要知道一个很重要的知识点,一 ...

  9. codeforces Round #252 (Div. 2) C - Valera and Tubes

    贪心算法,每条路径最短2格,故前k-1步每次走2格,最后一步全走完 由于数据比较小,可以先打表 #include <iostream> #include <vector> #i ...

  10. 关于vim插件

    本人比较喜欢amix它集成了很多插件. 1.mru.vim:用于打开最近使用过的文件 使用命令: :MRU     打开最近的文件列表 上下箭头可以移动关标 :o 在新窗口中打开文件 2.NERD T ...