【进度显示】progressbar进度条的使用
来源:互联网 发布:shader编程工具 编辑:程序博客网 时间:2024/04/29 03:10
ProgressBar是进度条组件,通常用于向用户展示某个耗时操作完成的进度,而不让用户感觉是程序失去了响应,从而更好地提升用户界面的友好性
ProgressBar的分类:有无进度条的分别
ProgressBar在XML设置
大环形progressBar:style=”?android:attr/progressBarStyleLarge”
中环形progressBar:style=不用设置
小环形progressBar: style=”?android:attr/progressBarStyleSmall”
水平的progressBar: style=”?android:attr/progressBarStyleHorizontal”
XML:ProgressBar属性
android:max="100"--最大显示进度 android:Progress="100"--第一显示进度 android:secondProgress="80"--第二显示进度 android:indeterminate="true"--设置是否精确显示true表示不精确显示、false表示精确
自定义ProgressBar样式
style="@android:style/Widget.ProgressBar.Horizontal"//安卓自带的一个风格 水平横向进度条android:progressDrawable="@drawable/progress_bar"//设置progressDrawable覆盖自带风格android:radius="5dip" 设置圆角android:startColor="#ff9d9e9d" 起始颜色android:centerColor="#ff5a5d5a" 中间颜色android:endColor="#ff747674" 终止颜色android:angle="270"
ProgressBar的关键方法
setProgress(int)设置第一进度setSecondaryProgress(int)设置第二进度 getProgress()获取第一进度 getSecondaryProgress()获取第二进度 incrementProgressBy(int)增加或减少第一进度 incrementSecondaryProgressBy(int)增加或减少第二进度 getMax()获取最大进度
ProgressDiglog的基础使用
proDialog=new ProgressDialog(MainActivity.this);//新建progressDialog对象proDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);//设置显示风格proDialog.setTitle("");//设置标题proDialog.setMessary("");//对话框里面的文字proDialog.setIcon(R.drawable.ic_launch);//设置图标proDialog.setMax(100);//进度条的最大值proDialog.incrementProgressBy(40);//设定初始化已经增长了的进度proDialog.setIndeterminate(false);//设定明确显示进度proDialog.setButton(whichButton,text,listener);//连接监听器proDialog.setButton(DialogInterface.BUTTON_POSITIVE,"确定",new //设定一个确认按钮proDialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int witch) { Toast.makeText(MainActivity.this ,"欢迎大家支持慕课网",Toast.LENGTH_SHORT).show(); }});proDialog.setCancelable(true);//设置为false后返回键不能退出,默认为trueproDialog.show();//显示对话框
源代码↓↓↓↓↓
package com.example.progressbar;import android.app.Activity;import android.app.Dialog;import android.app.ProgressDialog;import android.content.DialogInterface;import android.os.Bundle;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;/* * progressBar是进度条组件,通常用于向用户展示某个耗时操作完成进度 * 而不让用户感觉是程序失去了响应,从而更好地提升用户界面的友好性。 */public class MainActivity extends Activity implements OnClickListener { private ProgressBar progress; private Button add; private Button reduce; private Button reset; private TextView text; private ProgressDialog prodialog; private Button show; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 插入:启用窗口特征,启用带进度和不带进度的进度条 requestWindowFeature(Window.FEATURE_PROGRESS); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.activity_main); // 显示两种进度条:true就显示,false就消失 setProgressBarVisibility(true);// 可见刻度 setProgressBarIndeterminateVisibility(false);// 不可见 // Max=10000,最后一个值是9999 setProgress(9999); 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.text); show = (Button) findViewById(R.id.show); // getPrgress()获取第一、第二、最大进度条的进度 int first = progress.getProgress(); int second = progress.getSecondaryProgress(); int max = progress.getMax(); // 显示的文本百分比进度 text.setText("第一进度百分比" + (int) (first / (double) max * 100) + "% " + "第二进度百分比" + (int) (second / (double) max * 100) + "% "); // 添加各个进度器的监听器 add.setOnClickListener(this); reduce.setOnClickListener(this); reset.setOnClickListener(this); show.setOnClickListener(this); } public void onClick(View v) { switch (v.getId()) { case R.id.add: { // 增加第一进度第二进度的10个刻度 progress.incrementProgressBy(10); progress.incrementSecondaryProgressBy(10); break; } case R.id.reduce: { // 减少第一进度第二进度的10个刻度 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("帅帅嗒先锋真TM帅!"); // 设置图标 prodialog.setIcon(R.drawable.ic_launcher); /** * 设定关于ProgressBar的一些属性 */ // 最大进度为100 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) { Toast.makeText(MainActivity.this, "欢迎大家支持郑先锋", Toast.LENGTH_SHORT).show(); } }); // 是否可以通过返回按钮退出对话框 prodialog.setCancelable(true); // 显示progressDialog prodialog.show(); break; } } text.setText("第一进度百分比" + (int) (progress.getProgress() / (double) progress.getMax() * 100) + "% " + "第二进度百分比" + (int) (progress.getSecondaryProgress() / (double) progress.getMax() * 100) + "% "); }}
布局文件:↓↓↓↓↓
<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" > <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" /> <!-- ↓↓↓↓↓↓↓按住Ctrl然后点击style 查看或者修改进度条的调色和配置↓↓↓↓↓↓ --> <ProgressBar android:secondaryProgress="80" android:progress="50" style="@android:style/Widget.ProgressBar.Horizontal" android:max="100" android:id="@+id/horiz" 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/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" android:text="TextView" /> <Button android:id="@+id/show" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/show" /></LinearLayout>
0 0
- 【进度显示】progressbar进度条的使用
- 使用ASP.NET Atlas编写显示真实进度的ProgressBar(进度条)控件
- 使用ASP.NET Atlas编写显示真实进度的ProgressBar(进度条)控件
- 使用ASP.NET Atlas编写显示真实进度的ProgressBar(进度条)控件
- 使用ASP.NET Atlas编写显示真实进度的ProgressBar(进度条)控件
- 使用ASP.NET Atlas编写显示真实进度的ProgressBar(进度条)控件
- 使用ASP.NETAtlas编写显示真实进度的ProgressBar(进度条)控件
- FLEX进度条ProgressBar不显示进度
- 使用带进度显示的圆形进度条
- ProgressBar---进度圈的显示
- Flex进度条控件ProgressBar使用讲解加载图片显示进度演示
- progressbar 进度条的使用
- 使用ASP.NET Atlas编写显示真实进度的ProgressBar
- ProgressBar使用自定义drawable时,进度显示不全的问题
- ProgressBar进度条10秒显示完成进度工作。
- ProgressBar进度条10秒显示完成进度工作--binbinyang
- c# progressBar进度条改变颜色及显示进度数字
- 使用C#在进度条中显示复制文件的进度
- CCF 其他简单问题算法思想
- fzu1479 字符串编码
- Hdu-5845 Best Division (trie+DP)
- 如何监听彩信的发送
- HDU 1257 最少拦截系统
- 【进度显示】progressbar进度条的使用
- Spring 读写分离
- 在virtualbox中,安装redhat系统,发现在/mnt下面,没有虚拟机设置的share文件夹,如何共享文件呢
- CCF 画图(1)
- 华为OJ——查找输入整数二进制中1的个数
- Android与H5页面的互调
- 缓存与数据库一致性保证
- LCD - 分辨率大全
- hibernate查询部分字段