android之进度条组件ProgressBar
首先是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的更多相关文章
- Android学习笔记(24):进度条组件ProgressBar及其子类
ProgressBar作为进度条组件使用,它还派生了SeekBar(拖动条)和RatingBar(星级评分条). ProgressBar支持的XML属性: Attribute Name Related ...
- 【Android 应用开发】 自定义 圆形进度条 组件
转载著名出处 : http://blog.csdn.net/shulianghan/article/details/40351487 代码下载 : -- CSDN 下载地址 : http://down ...
- progressbar进度条组件
Progressbar 进度条组件 通过$.fn.progressbar.fn.defaults重写默认的defaults进度条(progressbar)提供了一种显示长时间操作进度的反馈.进度可被更 ...
- 第一百九十八节,jQuery EasyUI,ProgressBar(进度条)组件
jQuery EasyUI,ProgressBar(进度条)组件 学习要点: 1.加载方式 2.属性列表 3.事件列表 4.方法列表 本节课重点了解 EasyUI 中 ProgressBar(进度条) ...
- 详解Bootstrap进度条组件
在网页中,进度条的效果并不少见,如:平分系统.加载状态等,进度条组件使用了css3的transition和animation属性来完成一些特效,这些特效在IE9及IE9以下版本.Firefox的老版本 ...
- Android 设置进度条背景
Android 设置进度条背景 直接上代码 <ProgressBar android:id="@+id/progressBar" android:layout_width=& ...
- android 自定义进度条颜色
android 自定义进度条颜色 先看图 基于产品经理各种自定义需求,经过查阅了解,下面是自己对Android自定义进度条的学习过程! 这个没法了只能看源码了,还好下载了源码, sources\b ...
- Android之进度条2
我之前有写过一篇“Android之进度条1”,那个是条形的进度条(显示数字进度),这次实现圆形进度条. 点击查看Android之进度条1:http://www.cnblogs.com/caidupin ...
- android的进度条使用
android的进度条 1.实现的效果 2.布局代码 先写一个my_browser.xml文件 存放WebView <?xml version="1.0" encoding= ...
随机推荐
- Servlet请求头response应用简单案例
Servlet请求头response应用简单案例:访问AServlet重定向到BServlet,5秒后跳到CServlet,并显示图片: AServlet package cn.yzu; import ...
- Tomcat不输入项目名进入自己项目(根目录指向自己的项目)
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDepl ...
- JavaScript设计模式——前奏(封装和信息隐藏)
前面一篇讲了js设计模式的前奏,包括接口的讲解.. 三:封装和信息隐藏: 信息隐藏用来进行解耦,定义一些私有的数据和方法. 封装是用来实现信息隐藏的技术,通过闭包实现私有数据的定义和使用. 接口在这其 ...
- Http协议提要
HTTP协议提要 简单来说,HTTP就是一个基于应用层的通信规范:双方要进行通信,大家就要遵守一个规范---HTTP协议.HTTP协议从WWW服务器超文本到本地浏览器 ,可以使浏览器更加高效.HTTP ...
- Android MVP理解
Android默认采用的是MVC: View:对应于布局文件 Model:业务逻辑和实体模型 Controllor:对应于Activity 但是却存在很多问题: 1.这个View对应于布局文件,其实能 ...
- DSP using MATLAB示例Example3.6
代码: n = [-5:5]; x = (-0.9).^n; % x(n) = k = -200:200; w = (pi/100)*k; % [0,pi] axis divided into 101 ...
- [工作中的设计模式]单例模式singleton
一.模式解析: 单例模式是最简单和最常用的设计模式,面试的时候,不管新毕业的学生还是已经工作多年的筒子,对单例模式基本都能聊上两句.单例模式主要体现在如下方面: 1.类的构造函数私有化,保证外部不能直 ...
- AutoMapper简明教程(学习笔记)
].FirstName + nameDto12[].LastName);Console.WriteLine();//Console.ReadKey();//emitMapper error//List ...
- 使用Spring的JAVA Mail支持简化邮件发送
http://www.cnblogs.com/codeplus/archive/2011/11/03/2232893.html
- Android 横屏切换竖屏Activity的生命周期(转)
曾经遇到过一个面试题,让你写出横屏切换竖屏Activity的生命周期.现在给大家分析一下他切换时具体的生命周期是怎么样的: 1.新建一个Activity,并把各个生命周期打印出来 2.运行Acti ...