Android进度条控件ProgressBar使用
ProgressBar有四种样式,圆形的(大,中,小)和直条形的(水平)
对应的style为
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <ProgressBar
android:id="@+id/progressBar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <ProgressBar
android:id="@+id/progressBar3"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <ProgressBar
android:id="@+id/progressBar4"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> </LinearLayout>
注:style不写默认为中型进度条
使用requestWindowFeature来实现带进度条的标题栏
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window; public class MainActivity extends ActionBarActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//启用精确显示进度的进度条和不显示精度的进度条标题栏
requestWindowFeature(Window.FEATURE_PROGRESS);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main); //设置可见性
setProgressBarVisibility(true);
setProgressBarIndeterminateVisibility(true);
//设置精确进度条的值,默认10000上限,达到10000后进度条不显示
setProgress(9999);
} }
在activity中对ProgressBar进行简单操作
用TextView实时显示第一进度条和第二进度条
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView; public class MainActivity extends ActionBarActivity implements OnClickListener{
private ProgressBar progress;
private Button add, reduce, reset;
private TextView text; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置无标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
//初始化
init();
} private void init() {
progress = (ProgressBar) findViewById(R.id.horiz);
add = (Button) findViewById(R.id.add);
reduce = (Button) findViewById(R.id.reduce);
reset = (Button) findViewById(R.id.reset);
text = (TextView) findViewById(R.id.textView1); //获取第一进度条进度
int first = progress.getProgress();
//获取第二进度条进度
int second = progress.getSecondaryProgress();
//获取最大进度
int max = progress.getMax();
text.setText(
"第一进度百分比:"+(int)(first/(float)max*100)+
"% 第二进度百分比:"+(int)(second/(float)max*100)+"%");
add.setOnClickListener(this);
reduce.setOnClickListener(this);
reset.setOnClickListener(this);
} @Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.add:
//增加第一进度条和第二进度条
progress.incrementProgressBy(10);
progress.incrementSecondaryProgressBy(10);
break;
case R.id.reduce:
progress.incrementProgressBy(-10);
progress.incrementSecondaryProgressBy(-10);
break;
case R.id.reset:
progress.setProgress(50);
progress.setSecondaryProgress(80);
break;
}
text.setText(
"第一进度百分比:"+(int)(progress.getProgress()/(float)progress.getMax()*100)+
"% 第二进度百分比:"+(int)(progress.getSecondaryProgress()/(float)progress.getMax()*100)+"%"); } }
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <ProgressBar
android:id="@+id/progressBar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <ProgressBar
android:id="@+id/progressBar3"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <ProgressBar
android:id="@+id/horiz"
android:max="100"
android:secondaryProgress="80"
android:progress="50"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> <Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bt1" /> <Button
android:id="@+id/reduce"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bt2" /> <Button
android:id="@+id/reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bt3" /> <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" /> </LinearLayout>
使用Dialog形式
import android.support.v7.app.ActionBarActivity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast; public class MainActivity extends ActionBarActivity{
private ProgressDialog progress; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置无标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main); init();
} private void init() {
//设置ProgressDialog的显示 //新建对象
progress = new ProgressDialog(this);
//设置风格
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
//设置标题
progress.setTitle("reading");
//设置文本内容
progress.setMessage("please waiting");
//设置图标
progress.setIcon(R.drawable.ic_launcher); progress.setMax(100);
progress.incrementProgressBy(50);
//是否非精确显示
progress.setIndeterminate(false);
progress.setButton(DialogInterface.BUTTON_POSITIVE, "确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//此处不能写this
Toast.makeText(MainActivity.this, "ok...", Toast.LENGTH_SHORT).show();
}
});
//是否可以点击取消键(android自带的返回键)
progress.setCancelable(false);
//显示
progress.show();
} }
Android进度条控件ProgressBar使用的更多相关文章
- [转载]ExtJs4 笔记(8) Ext.slider 滚轴控件、 Ext.ProgressBar 进度条控件、 Ext.Editor 编辑控件
作者:李盼(Lipan)出处:[Lipan] (http://www.cnblogs.com/lipan/)版权声明:本文的版权归作者与博客园共有.转载时须注明本文的详细链接,否则作者将保留追究其法律 ...
- ExtJs4 笔记(8) Ext.slider 滚轴控件、 Ext.ProgressBar 进度条控件、 Ext.Editor 编辑控件
本篇要登场的有三个控件,分别是滚轴控件.进度条控件和编辑控件. 一.滚轴控件 Ext.slider 1.滚轴控件的定义 下面我们定义三个具有代表意义滚轴控件,分别展示滚轴横向.纵向,以及单值.多值选择 ...
- C# 根据BackgroundWoker异步模型和ProgressBar控件,自定义进度条控件
前言 程序开发过程中,难免会有的业务逻辑,或者算法之类产生让人能够感知的耗时操作,例如循环中对复杂逻辑处理;获取数据库百万乃至千万级数据;http请求的时候等...... 用户在使用UI操作并不知道程 ...
- Photoshop和WPF双剑配合,打造炫酷个性的进度条控件
现在如果想打造一款专业的App,UI的设计和操作的简便性相当重要.UI设计可以借助Photoshop或者AI等设计工具,之前了解到WPF设计工具Expression Blend可以直接导入PSD文件或 ...
- [K/3Cloud]进度条控件编程接口
进度条控件编程接口 1.启动进度查询 this.GetControl<ProgressBar>().Start(2) //每2秒查询一次进度 2.汇报进度 在插件中重载 OnQueryP ...
- DevExpress的进度条控件ProgressBarControl的使用-以ZedGraph添加曲线进度为例
场景 Winform控件-DevExpress18下载安装注册以及在VS中使用: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1 ...
- 用 CALayer 定制下载进度条控件
// // RPProgressView.h // CALayer定制下载进度条控件 // // Created by RinpeChen on 16/1/2. // Copyright © 2016 ...
- 【转】用emWin进度条控件做个表盘控件,效果不错
@2018-08-09 用emWin进度条控件做个表盘控件,效果不错
- 为OLED屏添加GUI支持6:进度条控件
为OLED屏添加GUI支持6:进度条控件 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 环境: 主机:WIN10 开发环境:MDK5.13 MCU:S ...
随机推荐
- Django——11 状态保持 form表单 登陆注册样例
Django 状态保持 用户状态例子 实现注册登陆实例 django forms 表单的使用 注册功能 登陆功能 状态保持cookie和session 1.http协议是无状态的:每次请求都是一次 ...
- Maven学习总结(3)——使用Maven构建项目
Maven学习总结(三)--使用Maven构建项目 maven作为一个高度自动化构建工具,本身提供了构建项目的功能,下面就来体验一下使用maven构建项目的过程. 一.构建Jave项目 1.1.创建J ...
- [TyvjP1515] 子串统计 [luoguP2408] 不同子串个数(后缀数组)
Tyvj传送门 luogu传送门 经典题 统计一个字符串中不同子串的个数 一个字符串中的所有子串就是所有后缀的前缀 先求出后缀数组,求出后缀数组中相邻两后缀的 lcp 那么按照后缀数组中的顺序遍历求解 ...
- [cogs736][网络流24题#13]星际转移[网络流,网络判定]
将一个空间站分为天数个点,每次枚举天数,每增加一天就把对应天数的边连上,用网络流判定可行性,即-判断最大流是否不小于k,注意编号不要错位.通过此题,可见一些网络流题目需要用到网络判定方法,但虽然答案具 ...
- POJ 1376 Robot
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7866 Accepted: 2586 Description The R ...
- sql server使用杂记
SqlServer导出数据库 navcat for sql server中打开连接,打开数据库,右键--数据传输,常规选项卡--模式选择dbo,目标选择连接(选择你新建的库)或者文件(导出你要的sql ...
- DirectX11 学习笔记8 - 最简单的光照
在上一个列子的基础上加了一个地面.这个地面是光照效果生成的. 看图: 先说明: 光照 须要重写一个 lightshader 就是光照的渲染器 // Define the input layout D ...
- WPF中控件TextBlock使用(简单)
TextBlock主要用来显示文字.比方: <TextBlock Name="txtBlockOutpuMessage" Text="hello" / ...
- WPF学习笔记——ListBox用ItemsSource绑定数据源
作为一个WPF初学者,感到困难重重.在网上想查个ListBox绑定数据源的示例,结果出来一大堆代码,一看心就烦. 我给个简洁一点的代码: 后台代码: protected class UserItem ...
- HDU 6069 Counting Divisors(2017 Multi-University Training Contest - Team 4 )
Output For each test case, print a single line containing an integer, denoting the answer. Sample ...