android中progress进度条的使用


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进度条的使用的更多相关文章
- Android 中带有进度条效果的按钮(Button)
安卓中带有进度条效果的按钮,如下图: 1.布局文件如下activity_main.xml <RelativeLayout xmlns:android="http://schemas.a ...
- 详解HTML5中的进度条progress元素简介及兼容性处理
一.progress元素基本了解 1.基本知识 progress元素属于HTML5家族,指进度条.IE10+以及其他靠谱浏览器都支持. 注释:Internet Explorer 9 以及更早的版本不支 ...
- android 对话框中的进度条 (ProgressDialog)
from:http://byandby.iteye.com/blog/817214 显然要定义对话框进度条就要用ProgressDialog,首先我们需要创建ProgressDialog对象,当然这里 ...
- Android View 之进度条+拖动条+星级评论条....
PS:将来的你会感谢现在奋斗的自己.... 学习内容: 1.进度条 2.拖动条 3.星级评论条 1.进度条... 进图条这东西想必大家是很熟悉的...为了使用户不会觉得应用程序死掉了,因此 ...
- Android 自学之进度条ProgressBar
进度条(ProgressBar)也是UI界面中的一种非常使用的组件,通常用于向用户显示某个耗时完成的百分比.因此进度条可以动态的显示进度,因此避免长时间地执行某个耗时操作时,让用户感觉程序失去了响应, ...
- 如何在UIAlertView中显示进度条
今天这个问题是,在一个iPhone程序中,我要在后台做大量的数据处理,希望在界面上显示一个进度条(Progress Bar)使得用户了解处理进度.这个进度条应该是在一个模态的窗口中,使界 今天这个问题 ...
- 【转】24. android dialog ——ProgressDialog 进度条对话框详解
原文网址:http://blog.csdn.net/jamesliulyc/article/details/6375598 首先在onCreateDialog方法里创建一个ProgressDialog ...
- Android——菜单和进度条
xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android= ...
- Xamarin XAML语言教程Xamarin.Forms中构建进度条
Xamarin XAML语言教程Xamarin.Forms中构建进度条 ProgressBar被称为进度条,它类似于没有滑块的滑块控件.进度条总是水平放置的.本节将讲解如何使用进度条. 注意:进度条在 ...
随机推荐
- 华为手机Edittext光标(cursor)颜色修改
华为手机的emui系统经常让人发出“可以可以,这很华为”的感叹 这两天在edittext部分也发生了这样的事情 正常edittext光标的颜色和宽度都说可以修改的,只需要通过xml中的 textCur ...
- Sprint第三个冲刺(第三天)
一.Sprint介绍 任务进度: 二.Sprint周期 看板: 燃尽图:
- PowerDesigner的安装和数据库创建(转载)
此文描述详细,特此转载,仅复制了大部分内容,可参考原文CodeSmith和PowerDesigner的安装和数据库创建(原创) 请大家不要用于商业用途哈,要支持正版,大家都是做软件的,知道开发一套软件 ...
- 环信SDK与Apple Watch的结合(3)
第3章主要介绍怎样在Watch App的页面上显示iPhone程序里的数据.主要操作的是“EMWatchOCDemo WatchKit Extension”这个文件夹,附源码EMWatchOCDemo ...
- 自定义动画方法animate
animate的使用方法:animate(params,speed,callback); 例子:animate({ right: "-=600px",height:"+= ...
- BI之SSAS完整实战教程4 -- 部署至SSAS进行简单分析
上一篇已经创建了多维数据集的结构. 接下来我们将多维数据集的架构定义发送到Analysis Services实例,部署到AS上去. 文章提纲 部署和浏览多维数据集 SSMS使用简介 总结 一.部署和浏 ...
- 不可或缺 Windows Native (2) - C 语言: 常量,变量,基本数据类型
[源码下载] 不可或缺 Windows Native (2) - C 语言: 常量,变量,基本数据类型 作者:webabcd 介绍不可或缺 Windows Native 之 C 语言 常量 变量 基本 ...
- csharp: NHibernate and Entity Framework (EF) (object-relational mapper)
代码生成器: 1. http://www.codesmithtools.com/ 2.https://sourceforge.net/projects/mygeneration/ 3. http:// ...
- 关于spring配置文件properties的问题
我遇到的问题是我将properties放在src下面的包中不能被spring扫描到,会报配置文件找不到的错误.但是如果放在src目录下就能够被spring扫描到,现在还不知道为什么这样,记个笔记,留到 ...
- [PHP] 读取大文件并显示
使用PHP读取日志文件,当文件比较大的时候,会报内存不足,因此应该部分读取,读取指定的行数的数据 PHP代码: <?php class Test{ //日志路径 const LOG_PATH=& ...