本文实例讲述了android中progressbar用法。分享给大家供大家参考,具体如下:

在android中会经常用到progressbar,下面通过举例来说明如何使用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.widget.button;

import android.widget.progressbar;

public class a03activity extends activity {

private progressbar rectangle,circle;

private button showprogressbar;

private final static int stop=0x10000;

private final static int next=0x10001;

private int count=0;

/** called when the activity is first created. */

@override

public void oncreate(bundle savedinstancestate) {

super.oncreate(savedinstancestate);

setcontentview(r.layout.main);

rectangle=(progressbar)findviewbyid(r.id.rectangle);

circle=(progressbar)findviewbyid(r.id.circle);

showprogressbar=(button)findviewbyid(r.id.showprogressbar);

rectangle.setindeterminate(false);

circle.setindeterminate(false);

showprogressbar.setonclicklistener(new onclicklistener(){

@override

public void onclick(view v) {

// todo auto-generated method stub

rectangle.setvisibility(view.visible);

circle.setvisibility(view.visible);

rectangle.setmax(100);

rectangle.setprogress(0);

circle.setprogress(0);

thread t=new thread(new runnable(){

@override

public void run() {

// todo auto-generated method stub

for(int i=0;i<20;i++){

try {

count=(i+1)*5;

thread.sleep(1000);

if(count==19){

message msg=new message();

msg.what=stop;

handler.sendmessage(msg);

break;

}

else{

message msg=new message();

msg.what=next;

handler.sendmessage(msg);

}

} catch (interruptedexception e) {

// todo auto-generated catch block

e.printstacktrace();

}

}

}

});

t.start();

}

});

}

private handler handler=new handler(){

@suppresswarnings("static-access")

public void handlemessage(message msg){

switch(msg.what){

case stop:

rectangle.setvisibility(view.gone);

circle.setvisibility(view.gone);

thread.currentthread().interrupt();

break;

case next:

if(!thread.currentthread().interrupted()){

rectangle.setprogress(count);

circle.setprogress(count);

}

break;

}

}

};

}

res/layout/main.xml如下所示:

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello" />

android:id="@+id/rectangle"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

style="?android:attr/progressbarstylehorizontal"

mce_style="?android:attr/progressbarstylehorizontal"

android:visibility="gone"

/>

android:id="@+id/circle"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

style="?android:attr/progressbarstylelarge"

mce_style="?android:attr/progressbarstylelarge"

android:visibility="gone"

/>

android:id="@+id/showprogressbar"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="show progressbar"

/>

更多关于android控件相关内容感兴趣的读者可查看本站专题:《android控件用法总结》

希望本文所述对大家android程序设计有所帮助。

android中的progressbar,Android中ProgressBar用法简单实例相关推荐

  1. velocity用法简单实例说明 .

    http://blog.csdn.net/renxianzuo/article/details/4457381 2009-08-18 01:48 3516人阅读 评论(8) 收藏 举报 velocit ...

  2. python timer怎么用_python定时器(Timer)用法简单实例

    python定时器(Timer)用法简单实例 本文实例讲述了python定时器(Timer)用法.分享给大家供大家参考.具体如下: # encoding: UTF-8 import threading ...

  3. android surface编程,Android中SurfaceView用法简单实例

    本文实例讲述了Android中SurfaceView用法.分享给大家供大家参考,具体如下: 这里贴上一个小程序代码,主要运用SurfaceView来实现在屏幕上画一个圆,你可以通过按方向键和触摸屏幕来 ...

  4. Android列表控件选项中添加进度框ProgressBar实现

        今天有时间就学习了下在ListView.GridView列表项中清加ProgressBar,小马用最简单的代码实现可以通用的功能,人人都能看懂,哈哈,直接说下,如果你的适配器getView方法 ...

  5. Android中list常用方法,Android中的常用控件及其基本用法

    TextView的使用方法 布局文件中的配置: 在Activity类中的使用: TextView textView1 = (TextView)findViewById(R.id.textView1); ...

  6. 【Android 安装包优化】Tint 着色器 ( 简介 | 布局文件中的 Tint 着色器基本用法 | 代码中使用 Tint 着色器添加颜色效果 )

    文章目录 一.Tint 着色器简介 二.布局文件中的 Tint 着色器基本用法 三.代码中使用 Tint 着色器添加颜色效果 四.参考资料 一.Tint 着色器简介 Tint 着色器的作用是是 可以使 ...

  7. (转)Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法

    版权声明:本文出自郭霖的博客,转载必须注明出处. 目录(?)[-] ValueAnimator的高级用法 ObjectAnimator的高级用法 转载请注明出处:http://blog.csdn.ne ...

  8. android 生成aar文件,Android 中.aar文件生成方法与用法

    https://i.cnblogs.com/EditPosts.aspx?opt=1 无论是用Eclipse还是用Android Studio做android开发,都会接触到jar包,全称应该是:Ja ...

  9. Android中list常用方法,Android中ListActivity用法实例分析

    本文实例分析了Android中ListActivity用法.分享给大家供大家参考,具体如下: 程序如下: import android.app.ListActivity; import android ...

  10. Android中Adapter适配器的介绍以及用法的总结

    Adapter(适配器的讲解) 适配器就我自己来看,我觉得这是一个非常重要的知识点,Adapter是用来帮助填出数据的中间桥梁,简单点说吧:将各种数据以合适的形式显示在View中给用户看.Adapte ...

最新文章

  1. centos 升级cmake from 2.* to 3.*
  2. 拼图游戏 复制粘贴一个叫lemene的人的,这个人是c++博客的用户,我不是,怕以后找不到这篇文章,所以复制粘贴了。文中最后给出了原文链接连接...
  3. GetListToJson
  4. Javascript数组操作方法
  5. 3DSlicer16:数据类型MRML
  6. 【蓝桥杯Java_C组·从零开始卷】第三节(附)、for循环练习题(数据题与图形题)
  7. 软件架构师的工作流程
  8. python做一个系统代码_python初学者,用python3实现基本的学生管理系统代码实例...
  9. mysql关闭显示无权限_如何关闭mysql远程登录权限
  10. [导入]Mobile Media API概述
  11. C语言实现2048游戏
  12. 计算机为什么硬盘值钱,数据到底有多值钱?看完硬盘数据恢复价格你就知道了...
  13. html中fixed属性,css中fixed是什么意思?
  14. KingbaseES Clusterware 高可用案例之---构建iSCSI共享存储
  15. 黑客为“炫技”随机攻击,结果被“顺着网线”抓了
  16. 关于DbVisualizer 6.0.14中的SQL语句显示中文问题
  17. 软件测试之linux环境搭建与操作Xshell、Xftp
  18. android 点击变色的两种情况、textview点击变色以及自定义checkbox
  19. 优秀课件笔记之计算机网络基础
  20. 什么是软件形式化方法

热门文章

  1. ntp服务器的搭建(内网时钟服务区的搭建)
  2. stringbuffer java API_java API中Object,String,Stringbuffer,StringBuilder的总结
  3. 小腹下面是什么部位_产后新妈妈去掉大肚腩,恢复平坦小腹,不妨试试这4个动作...
  4. 怎么解Linux内核温控,Linux Thermal 框架解析
  5. 命令行_Pytest之命令行执行
  6. oracle ora-27544,数据库启动后,大量报错ORA-27300
  7. c语言试讲课程,《C语言程序设计教程》试讲教案.doc
  8. linux 区别 挂起 阻塞_踩坑之java执行linux命令死锁阻塞挂起
  9. 浅谈SpringMVC的概念及执行原理
  10. 队列与栈(Queue,Deque,Stack)