怎样控制界面控件之进度条(ProgressBar)功能
一、基础知识:
1.ProgressBar在界面文件XML中的布局:
[html]
<progressBar android:id="@+id/progressbar_updown"
android:layout_width="200dp"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:layout_gravity="center_vertical"
android:max="100"
android:progress="50"
android:secondaryProgress="70" >
<progressBar android:id="@+id/progressbar_updown"
android:layout_width="200dp"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:layout_gravity="center_vertical"
android:max="100"
android:progress="50"
android:secondaryProgress="70" >
[plain]
style="?android:attr/progressBarStyleHorizontal" 设置风格为长形
android:max="100" 最大进度值为100
android:progress="50" 初始化的进度值
android:secondaryProgress="70" 初始化的底层第二个进度值
android:layout_gravity="center_vertical" 垂直居中
style="?android:attr/progressBarStyleHorizontal" 设置风格为长形
android:max="100" 最大进度值为100
android:progress="50" 初始化的进度值
android:secondaryProgress="70" 初始化的底层第二个进度值
android:layout_gravity="center_vertical" 垂直居中
2.ProgressBar在代码文件(.java)中的控制使用:
[java]
private ProgressBar myProgressBar;
//定义ProgressBar
myProgressBar = (ProgressBar) findViewById(R.id.progressbar_updown);
//ProgressBar通过ID来从XML中获取
myProgressBar.incrementProgressBy(5);
//ProgressBar进度值增加5
myProgressBar.incrementProgressBy(-5);
//ProgressBar进度值减少5
myProgressBar.incrementSecondaryProgressBy(5);
//ProgressBar背后的第二个进度条 进度值增加5
myProgressBar.incrementSecondaryProgressBy(-5);
//ProgressBar背后的第二个进度条 进度值减少5
private ProgressBar myProgressBar;
//定义ProgressBar
myProgressBar = (ProgressBar) findViewById(R.id.progressbar_updown);
//ProgressBar通过ID来从XML中获取
myProgressBar.incrementProgressBy(5);
//ProgressBar进度值增加5
myProgressBar.incrementProgressBy(-5);
//ProgressBar进度值减少5
myProgressBar.incrementSecondaryProgressBy(5);
//ProgressBar背后的第二个进度条 进度值增加5
myProgressBar.incrementSecondaryProgressBy(-5);
//ProgressBar背后的第二个进度条 进度值减少5
3.XML重要属性
android:progressBarStyle:默认进度条样式
android:progressBarStyleHorizontal:水平样式
4.重要方法
[plain]
getMax():返回这个进度条的范围的上限
getProgress():返回进度
getSecondaryProgress():返回次要进度
incrementProgressBy(int diff):指定增加的进度
isIndeterminate():指示进度条是否在不确定模式下
setIndeterminate(boolean indeterminate):设置不确定模式下
setVisibility(int v):设置该进度条是否可视
getMax():返回这个进度条的范围的上限
getProgress():返回进度
getSecondaryProgress():返回次要进度
incrementProgressBy(int diff):指定增加的进度
isIndeterminate():指示进度条是否在不确定模式下
setIndeterminate(boolean indeterminate):设置不确定模式下
setVisibility(int v):设置该进度条是否可视
二、代码展示:
1."Activity_09\src\yan\activity_09\MainActivity.java"
[java]
package yan.activity_09;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.app.Activity;
public class MainActivity extends Activity {
// 声明变量
private ProgressBar firstBar = null;
private ProgressBar secondBar = null;
private Button myButton = null;
private int progress_vol = 0;
@Override
protected 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 ButtonListenr());
}
class ButtonListenr implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(0 == progress_vol)
{
// 设置进度条的最大值
firstBar.setMax(200);
// 设置进度条为可见的状态
firstBar.setVisibility(View.VISIBLE);
secondBar.setVisibility(View.VISIBLE);
}else if(progress_vol < firstBar.getMax()){
// 设置主进度条的当前值
firstBar.setProgress(progress_vol);
// 设置第二进度条的当前值
firstBar.setSecondaryProgress(progress_vol+10);
// 默认的进度条是无法显示进行的状态的
//secondBar.setProgress(progress_vol);
}else{
// 设置进度条为不可见的状态
firstBar.setVisibility(View.GONE);
secondBar.setVisibility(View.GONE);
}
progress_vol +=10;
}
}
}
package yan.activity_09;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.app.Activity;
public class MainActivity extends Activity {
// 声明变量
private ProgressBar firstBar = null;
private ProgressBar secondBar = null;
private Button myButton = null;
private int progress_vol = 0;
@Override
protected 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 ButtonListenr());
}
class ButtonListenr implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(0 == progress_vol)
{
// 设置进度条的最大值
firstBar.setMax(200);
// 设置进度条为可见的状态
firstBar.setVisibility(View.VISIBLE);
secondBar.setVisibility(View.VISIBLE);
}else if(progress_vol < firstBar.getMax()){
// 设置主进度条的当前值
firstBar.setProgress(progress_vol);
// 设置第二进度条的当前值
firstBar.setSecondaryProgress(progress_vol+10);
// 默认的进度条是无法显示进行的状态的
//secondBar.setProgress(progress_vol);
}else{
// 设置进度条为不可见的状态
firstBar.setVisibility(View.GONE);
secondBar.setVisibility(View.GONE);
}
progress_vol +=10;
}
}
}
2."Activity_09\res\layout\main.xml"
[html]
<?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"
android:background="#00aaaa"
>
<TextView
android:id="@+id/firstText"
android:text="@string/hello_world"
android:gravity="center_vertical"
android:textSize="15pt"
android:background="#aa0000"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"/>
<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>
<?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"
android:background="#00aaaa"
>
<TextView
android:id="@+id/firstText"
android:text="@string/hello_world"
android:gravity="center_vertical"
android:textSize="15pt"
android:background="#aa0000"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"/>
<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>
3."Activity_09\res\values\strings.xml"
[html]
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Activity_09</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Activity_09</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
</resources>
怎样控制界面控件之进度条(ProgressBar)功能的更多相关文章
- MFC控件编程进度条编写
MFC控件编程进度条编写 一丶进度条编程需要用到的方法 进度条MFC已经帮我们封装好类了. 叫做 CProgressCtrl 进度条编程也很简单. 封装的方法也就那个那几个. GetPos() 获 ...
- C# 根据BackgroundWoker异步模型和ProgressBar控件,自定义进度条控件
前言 程序开发过程中,难免会有的业务逻辑,或者算法之类产生让人能够感知的耗时操作,例如循环中对复杂逻辑处理;获取数据库百万乃至千万级数据;http请求的时候等...... 用户在使用UI操作并不知道程 ...
- Android自己定义控件:进度条的四种实现方式
前三种实现方式代码出自: http://stormzhang.com/openandroid/2013/11/15/android-custom-loading/ (源代码下载)http://down ...
- 2015.3.11 VS异步控件及进度条结合应用
1.在Form中添加 指针控件:BackgroundWorker-bgwork:进度条控件progressBar1 以及开始.取消按钮 2.开始按钮启动异步线程 private void button ...
- Winform之跨线程访问控件(在进度条上显示字体)
此文章对于遇到必须使用线程但是没有办法在线程内操作控件的问题的处理 有很好的解决方案(个人认为的.有更好的方案欢迎交流.) 在做跨线程访问之前我们先了解下我们所做的需要达到的效果: 这个是批量的将x ...
- 【转】VC 多线程中控制界面控件的几种方法
原文网址:https://software.intel.com/zh-cn/blogs/2010/11/30/vc-3 为了保证界面的用户体验经常要把数据处理等放到子线程中进行,然后把结果更新到主界面 ...
- Android中的常用控件之进度条(ProgressBar)
ProgressBar的常用属性:style,进度条的样式,默认为圆形,用style="?android:attr/progressBarStyleHorizontal"可以将进度 ...
- 【Qt开发】Qt控件之进度条
QT 进度条操作实例是本文要介绍的内容,在QT中可以用QProgressBar或着QProgressDialog来实现进度条. QProgressBar的使用 首先在designer中拖一个按钮和 ...
- Android自己定义控件--圆形进度条(中间有图diao)
智能家居越来越流行,在智能家居中我们常要表现一些数据的百分比 圆形度条中间加个图是一种很流行的自己定义View 1.第一步 你首先须要对类进行继承View public class CirclePro ...
随机推荐
- unix命令: ifconfig
ifconfig 命令被用来: 1.为一个网卡分配一个IP地址 2.设置本地环路界面 3.分配一个子网掩码(可选) HP-UX: # /usr/sbin/ifconfig lan0 lan0: fla ...
- Qt多工程多目录的编译案例
源地址:http://blog.csdn.net/libaineu2004/article/details/23625441 写这篇文章的目的是为了让Qt像VC++那样,支持一个工程包含多个项目.即1 ...
- Thymeleaf Javascript 取值
<script th:inline="javascript"> var openid = /*[[${session.wxuser.openId}]]*/ </s ...
- 性能测试之LoadRunner11 破解
1. 下载破解文件lm70.dll和mlr5lprg.dll lm70.dll文件,覆盖x:\Program Files\Mercury\LoadRunner\bin下文件即可. ml ...
- oracle flashback 2
Flashback database After oracle 10g, oracle can rollback to an prior time by flashback databas ...
- CF 552C 进制转换
http://codeforces.com/problemset/problem/552/C C. Vanya and Scales time limit per test 1 second memo ...
- Swift - 设置网格UICollectionView的单元格间距
要设置单元格cell的间距(水平间距,垂直间距)可进行如下设置: 方法1:在storyboard中设置 选择Collection View后在面板里设置Min Spacing相关属性(这里也可以设置单 ...
- 5.单行函数,多行函数,字符函数,数字函数,日期函数,数据类型转换,数字和字符串转换,通用函数(case和decode)
1 多行函数(理解:有多个输入,但仅仅输出1个结果) SQL>select count(*) from emp; COUNT(*) ------------- 14 B 字符函数Lowe ...
- webdynpro 调用应用程序做跳转
1.是调用指的是调用生成应用程序,非webdynpro组件程序, 如下: 1)调用页面,并传值 METHOD get_zgmtpage . DATA:lw_application_name TYPE ...
- Vmware linux 安装 Vmware Tools 提示只读
在Vmware 虚拟机里安装完linux ,安装Vmware Tools,的时候会提示只读问题,是因为在安装 Vmware Tools 使用的是光盘挂在,光盘为只读文件,所以没有办法再光盘上直接的解压 ...