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被称为进度条,它类似于没有滑块的滑块控件.进度条总是水平放置的.本节将讲解如何使用进度条. 注意:进度条在 ...
随机推荐
- mybatis中#和$符号的区别
mybatis做为一个轻量级ORM框架在许多项目中使用,因其简单的入门受到了广大开发者的热爱.在近期项目中再做一个相关的开发,碰到了#.$符号这样的问题,之前没怎么注意过,通过学习之后,有了点感悟,分 ...
- C++ 面向对象的三个特点--多态性(二)
运算符重载 运算符重载,就是对已有的运算符重新进行定义,赋予其另一种功能,以适应不同的数据类型. 类外部的运算符重载 首先,我们通过一个例子来说明为什么要有运算符重载. // Complex.h cl ...
- C#中List<T>对象的深度拷贝问题
一.List<T>对象中的T是值类型的情况(int 类型等) 对于值类型的List直接用以下方法就可以复制: List<T> oldList = new List<T&g ...
- java微信开发(wechat4j)——发送客服消息
微信支持主动发送客服消息.如果你要实现此功能,需要使用CustomerMsg类. 获得access_token access_token请求之后有一个过期时间,微信平台建议你使用一个中控服务器来定时刷 ...
- Linux 学习手记(4):Linux系统常用Shell命令
日期时间 date命令:显示当前时间日期 date -u # 显示格林威治(UTC)事件 date +%Y-%m-%d # 格式显示日期 date -s '20:25:25' # 修改系统时间,需要使 ...
- Visual Studio添加dll程序集引用操作步骤
Visual Studio 中添加引用的操作: 在“解决方案资源管理器”中,先右击项目图标,在弹出菜单选择“添加引用...” 然后在弹出的窗口中选择所要添加的选项,点击确定就可以了. 原文:http: ...
- ABAP内表(internal table)有关的系统变量
SY-TABIX – 内表当前行的索引号.SY-TABIX 的值可以被以下命令修改,但是只适用于索引表(index table).对于哈希表(Hashed table),这个系统变量的值为空或0. A ...
- MSCRM 修改 默认组织
目前组织管理器上的方法是无效的,期待MS打补丁吧. 下面介绍修改DB的方法: 1)打开Sql server management,找到MSCRM_config数据库,打开数据表:SystemUser和 ...
- 安卓开发_慕课网_ViewPager与FragmentPagerAdapter实现Tab实现Tab(App主界面)
学习内容来自“慕课网” ViewPager与FragmentPagerAdapter实现Tab 将这两种实现Tab的方法结合起来.效果就是可以拖动内容区域来改变相应的功能图标亮暗 思路: Fragme ...
- Android—Ormlite框架简单的操作数据库
大家在Android项目中或多或少的都会使用数据库,为了提高我们的开发效率,当然少不了数据库ORM框架了,尤其是某些数据库操作特别频繁的app:本篇博客将详细介绍ORMLite的简易用法. 下面开始介 ...