activity.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.demo13.MainActivity" >

<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></ProgressBar>

<ProgressBar
android:id="@+id/progressBar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></ProgressBar>

<ProgressBar
android:id="@+id/progressBar3"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></ProgressBar>

<ProgressBar
android:id="@+id/progressBar4"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="50"
android:secondaryProgress="80" >
</ProgressBar>

<Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add" />

<Button
android:id="@+id/reduce"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/reduce" />

<Button
android:id="@+id/reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/reset" />

<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

<Button
android:id="@+id/show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/show" />

</LinearLayout>

main.java

package com.example.demo13;

import android.support.v7.app.ActionBarActivity;
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 implements OnClickListener{

private ProgressBar progress;
private Button add;
private Button reduce;
private Button reset;
private TextView text;
private ProgressDialog prodialog;
private Button show;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_PROGRESS);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main);

setContentView(R.layout.activity_main);
setProgressBarVisibility(true);
setProgressBarIndeterminateVisibility(true);
setProgress(600);
init();

}
private void init() {
progress=(ProgressBar) findViewById(R.id.progressBar4);
add=(Button) findViewById(R.id.add);
reduce=(Button) findViewById(R.id.reduce);
reset=(Button) findViewById(R.id.reset);
text=(TextView) findViewById(R.id.text);
show=(Button) findViewById(R.id.show);
show.setOnClickListener(this);
//获取第一进度条
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);
}
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;
}
case R.id.show:{
//新建ProgressDialog对象
prodialog=new ProgressDialog(MainActivity.this);
//设置显示风格
prodialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
//设置标题
prodialog.setTitle("刀冲");
//设置对话框里的文字信息
prodialog.setMessage("欢迎大家访问我的博客");
//设置图标
prodialog.setIcon(R.drawable.ic_launcher);

//设置进度条属性
prodialog.setMax(100);
prodialog.incrementProgressBy(50);
//进度条是明确显示进度的
prodialog.setIndeterminate(false);

//设定一个确定按钮
prodialog.setButton(DialogInterface.BUTTON_POSITIVE,"确定",new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this,"刀冲的博客园",Toast.LENGTH_SHORT).show();
}
});
//可不可以通过返回按钮退出对话框
prodialog.setCancelable(true);

//显示ProgressDialog
prodialog.show();

break;
}
}
text.setText("第一进度百分比"+(int)(progress.getProgress()/(float)progress.getMax()*100)+"% 第二进度百分比"+(int)(progress.getSecondaryProgress()/(float)progress.getMax()*100)+"%");

}

}

android中progress进度条的使用的更多相关文章

  1. Android 中带有进度条效果的按钮(Button)

    安卓中带有进度条效果的按钮,如下图: 1.布局文件如下activity_main.xml <RelativeLayout xmlns:android="http://schemas.a ...

  2. 详解HTML5中的进度条progress元素简介及兼容性处理

    一.progress元素基本了解 1.基本知识 progress元素属于HTML5家族,指进度条.IE10+以及其他靠谱浏览器都支持. 注释:Internet Explorer 9 以及更早的版本不支 ...

  3. android 对话框中的进度条 (ProgressDialog)

    from:http://byandby.iteye.com/blog/817214 显然要定义对话框进度条就要用ProgressDialog,首先我们需要创建ProgressDialog对象,当然这里 ...

  4. Android View 之进度条+拖动条+星级评论条....

    PS:将来的你会感谢现在奋斗的自己.... 学习内容: 1.进度条 2.拖动条 3.星级评论条 1.进度条...       进图条这东西想必大家是很熟悉的...为了使用户不会觉得应用程序死掉了,因此 ...

  5. Android 自学之进度条ProgressBar

    进度条(ProgressBar)也是UI界面中的一种非常使用的组件,通常用于向用户显示某个耗时完成的百分比.因此进度条可以动态的显示进度,因此避免长时间地执行某个耗时操作时,让用户感觉程序失去了响应, ...

  6. 如何在UIAlertView中显示进度条

    今天这个问题是,在一个iPhone程序中,我要在后台做大量的数据处理,希望在界面上显示一个进度条(Progress Bar)使得用户了解处理进度.这个进度条应该是在一个模态的窗口中,使界 今天这个问题 ...

  7. 【转】24. android dialog ——ProgressDialog 进度条对话框详解

    原文网址:http://blog.csdn.net/jamesliulyc/article/details/6375598 首先在onCreateDialog方法里创建一个ProgressDialog ...

  8. Android——菜单和进度条

    xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android= ...

  9. Xamarin XAML语言教程Xamarin.Forms中构建进度条

    Xamarin XAML语言教程Xamarin.Forms中构建进度条 ProgressBar被称为进度条,它类似于没有滑块的滑块控件.进度条总是水平放置的.本节将讲解如何使用进度条. 注意:进度条在 ...

随机推荐

  1. [JS] JavaScript框架(1) jQuery

    jQuery使用户能更方便地处理HTML(标准通用标记语言下的一个应用).events.实现动画效果,并且方便地为网站提供AJAX交互.jQuery还有一个比较大的优势是,它的文档说明很全,而且各种应 ...

  2. [Tool] WireShark基本使用

    Wireshark(前称Ethereal)是一个网络封包分析软件. 在windows平台上,Wireshark使用WinPCAP作为接口,直接与网卡进行数据报文交换. [参数设置]: 抓包参数(Cap ...

  3. 数论 --- 费马小定理 + 快速幂 HDU 4704 Sum

    Sum Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=4704 Mean: 给定一个大整数N,求1到N中每个数的因式分解个数的 ...

  4. 重构第30天 尽快返回 (Return ASAP)

    理解:把条件语句中复杂的判断用尽快返回来简化. 详解:如首先声明的是前面讲的”分解复杂判断“,简单的来说,当你的代码中有很深的嵌套条件时,花括号就会在代码中形成一个长长的箭头.我们经常在不同的代码中看 ...

  5. [CLR via C#]21. 自动内存管理(垃圾回收机制)

    目录 理解垃圾回收平台的基本工作原理 垃圾回收算法 垃圾回收与调试 使用终结操作来释放本地资源 对托管资源使用终结操作 是什么导致Finalize方法被调用 终结操作揭秘 Dispose模式:强制对象 ...

  6. windbg学习进阶之——dump分析常用命令收集

    #重要说明 (1) windbg命令分为标准命令,元命令和扩展命令. 标准命令提供最基本的调试功能,不区分大小写.如:bp  g  dt  dv  k等 元命令提供标准命令没有提供的功能,也内建在调试 ...

  7. Can you explain Lazy Loading?

    Introduction Lazy loading is a concept where we delay the loading of the object until the point wher ...

  8. fibonacci数列从a到b的个数

    Description 我们定义斐波那契数列如下: f1=1 f2=2 f(n)=f(n-1)+f(n-2)(n>=3)   现在,给定两个数a和b,计算有多少个斐波那契数列中的数在a和b之间( ...

  9. Scala underscore的用途

    _ 的用途 // import all import scala.io._ // import all, but hide Codec import scala.io.{Codec => _, ...

  10. CentOS常用指令

    创建文件: 如touch a.txt 创建文件夹: mkdir -p 文件夹名,当文件夹不存在时候,创建这个文件夹 文件重命名: 把文件text.php得命名为index.php,可以是rename ...