Android程序:进度条(ProgressBar)的使用方法和案例
来源:互联网 发布:php空间服务器 编辑:程序博客网 时间:2024/06/06 01:10
基本用法:
MainActivity :
public class MainActivity extends Activity implements OnClickListener { private ProgressBar progressBar; private Button btAdd; private Button btReduce; private Button btReSet; private TextView text; private ProgressDialog progressDialog; private Button btShow; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); progressBar = (ProgressBar) findViewById(R.id.progressBar); btAdd = (Button) findViewById(R.id.add); btReduce = (Button) findViewById(R.id.reduce); btReSet = (Button) findViewById(R.id.reset); text = (TextView) findViewById(R.id.text); btShow = (Button) findViewById(R.id.show); // 获取第一条进度条的进度 int first = progressBar.getProgress(); // 获取第二条进度条的进度 int second = progressBar.getSecondaryProgress(); // 获取进度条的最大进度 int max = progressBar.getMax(); text.setText("第一进度百分比:" + (int) (first * 100.0 / max) + "%,第二进度百分比:" + (int) (second * 100.0 / max) + "%"); btAdd.setOnClickListener(this); btReduce.setOnClickListener(this); btReSet.setOnClickListener(this); btShow.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.add: // 两个进度都增加10个刻度 progressBar.incrementProgressBy(10); progressBar.incrementSecondaryProgressBy(10); break; case R.id.reduce: progressBar.incrementProgressBy(-10); progressBar.incrementSecondaryProgressBy(-10); break; case R.id.reset: progressBar.setProgress(50); progressBar.setSecondaryProgress(80); break; case R.id.show: //新建ProgressDialog对象 progressDialog=new ProgressDialog(this); //设置显示风格 progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); //设置标题 progressDialog.setTitle("对话框进度条"); //设置对话框中的文字 progressDialog.setMessage("这是对话框进度条"); //设置图标 progressDialog.setIcon(R.drawable.ic_launcher); /** * 设定关于ProgressBar的一些属性 */ //设定最大进度 progressDialog.setMax(100); //设定初始化的进度 progressDialog.incrementProgressBy(50); //进度条是明确显示进度的 progressDialog.setIndeterminate(false); /** * 设定一个确定按钮 */ progressDialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, "点了确定", Toast.LENGTH_SHORT).show(); } }); //是否可以通过返回按钮退出对话框 progressDialog.setCancelable(true); //显示ProgressDialog progressDialog.show(); break; } text.setText("第一进度百分比:" + (int) (progressBar.getProgress() * 100.0 / progressBar .getMax()) + "%,第二进度百分比:" + (int) (progressBar.getSecondaryProgress() * 100.0 / progressBar .getMax()) + "%"); }}
main.xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <!-- android:progressDrawable="" 可以定义配色方案 --> <ProgressBar android:id="@+id/progressBar" style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:max="100" android:progress="50" android:secondaryProgress="80" /> <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>
0 0
- Android程序:进度条(ProgressBar)的使用方法和案例
- Android ProgressBar(进度条)的使用方法
- ProgressBar(进度条)的使用案例
- Android的Activity跳转和ProgressBar进度条
- Android自定义进度条(ProgressBar)的问题
- 01-13-1:ProgressBar(进度条)的使用方法
- Android ProgressBar的案例
- ProgressBar-进度条案例
- Android ProgressBar进度条的使用
- Android ProgressBar进度条的使用
- Android ProgressBar进度条的创建
- Android progressbar 进度条的使用
- Handler结合progressBar(进度条)使用方法
- android中的ProgressBar(进度条)
- Android的ProgressBar进度条-android学习之旅(三十一)
- Android AsyncTask下载图片和ProgressBar进度条
- Android 几种 PROGRESSBAR的属性(进度条)
- Android 几种 PROGRESSBAR的属性(进度条)
- yum 安装 mysql5.6
- 【LeetCode从零单刷】N-Queens II
- jdp实现分页
- Linux安装配置php
- pokers -end
- Android程序:进度条(ProgressBar)的使用方法和案例
- XSS的常见变换--XSS攻击发展
- iOS中UIScrollView嵌套UIImageView实现图片滑动浏览、缩放
- 开心的小明
- 技术中的喜闻乐见,不用session存放验证码
- 百度地图使用小技巧
- MySQL 优化(必看 必看)
- vsftpd 530 login incorrect on ubuntu
- [搜狗测试]自动化测试后台揭秘