点击按钮模拟进度条下载进度,“下载”完成进度条消失。

代码如下:

xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ProgressBar
android:id="@+id/firstBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:visibility="gone"
/>
<ProgressBar
android:id="@+id/secondBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>
<Button
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="begin"
/>
</LinearLayout>

Activity:

package ydl.progressbar;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar; public class ProgressBarTest extends Activity {
/** Called when the activity is first created. */
//声明变量
private ProgressBar firstBar =null;
private ProgressBar secondBar = null;
private Button myButton = null;
private int i = 0 ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//根据控件的ID来取得代表控件的对象
firstBar = (ProgressBar)findViewById(R.id.firstBar);
secondBar = (ProgressBar)findViewById(R.id.secondBar);
myButton = (Button)findViewById(R.id.myButton);
myButton.setOnClickListener(new ButtonListener());
}
class ButtonListener implements OnClickListener{ @Override
public void onClick(View v) {
if(i == 0)
{
//设置进度条处于可见的状态
firstBar.setVisibility(View.VISIBLE);
firstBar.setMax(150);//手动设置最大值,默认是100
secondBar.setVisibility(View.VISIBLE);
}
else if ( i < firstBar.getMax()){
//设置主进度条的当前值
firstBar.setProgress(i);
//设置第二进度条的当前值
firstBar.setSecondaryProgress(i + 10);
//因为默认的进度条无法显示进行的状态
//secondBar.setProgress(i); }
else{
//设置进度条处于不可见状态
firstBar.setVisibility(View.GONE);
secondBar.setVisibility(View.GONE);
}
i = i + 10 ;
} } }

Android简易实战教程--第二话《两种进度条》的更多相关文章

  1. Android简易实战教程--第一话《最简单的计算器》

    转载请注明出处:http://blog.csdn.net/qq_32059827/article/details/51707931 从今天开始,本专栏持续更新Android简易实战类博客文章.和以往专 ...

  2. Android简易实战教程--第二十二话《自定义组合控件模拟qq登录下拉框和其中的一些”小技巧”》

    转载此文章请注明出处:点击打开链接   http://blog.csdn.net/qq_32059827/article/details/52313516 首先,很荣幸此专栏能被CSDN推荐到主页.荣 ...

  3. Android简易实战教程--第二十九话《创建图片副本》

    承接第二十八话加载大图片,本篇介绍如何创建一个图片的副本. 安卓中加载的原图是无法对其修改的,因为默认权限是只读的.但是通过创建副本,就可以对其做一些修改,绘制等了. 首先创建一个简单的布局.一个放原 ...

  4. Android简易实战教程--第二十六话《网络图片查看器在本地缓存》

    本篇接第二十五话  点击打开链接   http://blog.csdn.net/qq_32059827/article/details/52389856 上一篇已经把王略中的图片获取到了.生活中有这么 ...

  5. Android简易实战教程--第二十八话《加载大图片》

    Android系统以ARGB表示每个像素,所以每个像素占用4个字节,很容易内存溢出.假设手机内存比较小,而要去加载一张像素很高的图片的时候,就会因为内存不足导致崩溃.这种异常是无法捕获的 内存不足并不 ...

  6. Android简易实战教程--第二十七话《自定义View入门案例之开关按钮详细分析》

    转载此博客请注明出处点击打开链接       http://blog.csdn.net/qq_32059827/article/details/52444145 对于自定义view,可能是一个比较大的 ...

  7. Android简易实战教程--第二十五话《网络图片查看器》

    访问网络已经有了很成熟的框架.这一篇只是介绍一下HttpURLConnection的简单用法,以及里面的"注意点".这一篇可以复习或者学习HttpURLConnection.han ...

  8. Android简易实战教程--第二十四话《画画板》

    今天完成一个画画板. 首先来个布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android ...

  9. Android简易实战教程--第二十三话《绚丽的菜单项》

    转载本博客请注明出处:点击打开链接  http://blog.csdn.net/qq_32059827/article/details/52327456 今天这篇稍微增强点代码量,可能要多花上5分钟喽 ...

随机推荐

  1. 使用JdbcTemplate 操作PostgreSQL,当where条件中有timestamp类型时,报错operator does not exist: timestamp w/out timezone

    今天遇到一个问题,找了还半天,Google一下,官网显示是一个bug. 思考一番肯定是类型出了问题. Controller: Service:转化时间戳 Dao: 一波转换搞定!

  2. 2018年Java实习春招总结

    因为女票在北京,打算去北京实习,所以从去年12月开始复习Java,做项目,视频是看的黑马的视频,还可以吧,把Java基础和SSM框架看了下,做了个小项目,然后看牛客网的中级项目课,做了一个健身头条项目 ...

  3. java线程与进程

    Java线程与进程 进程与线程的关系 进程里面至少有一个线程,进程间的切换会有较大的开销 线程必须依附在进程上,同一进程共享代码和数据空间 多线程的优势 多线程可以达到高效并充分利用cpu 线程使用的 ...

  4. struts2中action的class属性值意义

    整合了spring就不同了,orz struts2单独使用时action由struts2自己负责创建:与spring集成时,action实例由spring负责创建(依赖注入).这导致在两种情况下str ...

  5. 转:Kafka 客户端TimeoutException问题之坑

    原文出自:http://www.jianshu.com/p/2db7abddb9e6 各种TimeoutException问题 会抛出org.apache.kafka.common.errors.Ti ...

  6. [HCNA]VLAN配置Trunk接口

    实验目的 1.掌握Trunk端口的配置 2.掌握Trunk端口允许所有VLAN通过的配置方法 3.掌握Trunk端口允许特定VLAN通过的配置方法 4.理解干道链路的应用场景 实验仪器 eNSP 实验 ...

  7. ELK 6安装配置 nginx日志收集 kabana汉化

    #ELK 6安装配置 nginx日志收集 kabana汉化 #环境 centos 7.4 ,ELK 6 ,单节点 #服务端 Logstash 收集,过滤 Elasticsearch 存储,索引日志 K ...

  8. Android签名与权限的安全问题(3)

    签名和权限的作用 Android签名中使用到的一些加密技术有: 公/私钥, SHA1(CERT.SF,MANIFEST.MF), RSA(CERT.RSA), 消息摘要, 移动平台中的主流签名作用: ...

  9. Connection Reset By Peer 解析

    linux网络编程 Connection reset by peer错误服务器向客户端发送了数据,客户端没有接收就关闭了,服务器read就会发生Connection reset by peer错误.我 ...

  10. Cassandra User 问题汇总(1)------------repair

    Cassandra Repair 问题 问1: 文档建议每周或者每月跑一次full repair.那么如果我是使用partition rangerepair,是否还有必要在cluster的每个节点上定 ...