ProgressBar 有几个重要的属性
<ProgressBar android:id="@+id/horiz" android:layout_width="match_parent" android:layout_height="wrap_content" style="?android:attr/progressBarStyleHorizontal" 这个是 横向显示 进度条 带有具体的进度用TextView显示进度条的进度style="?android:attr/progressBarStyleLarge"这个是 一直转圈的 进度条 就像查询网页 转圈那样android:max="100" 这是进度最大值 android:progress="50" 这是当前进度 也就是第一进度 android:secondaryProgress="70"/> 设置第二进度 相当于 看电影的时候 缓存的那个进度
max=horiz.getMax(); 获取最大进度 first=horiz.getProgress();第一进度 second=horiz.getSecondaryProgress();第二进度 textView.setText("第一进度条="+first*100/max+"% 第二进度条="+second*100/max+"%"); 当第一进度/最大进度 结果就是当前进度的值 乘以100 显示就是百分比的情况添加2个Button 来增加 进度 和减少进度
public void onClick(View v) { switch (v.getId()) { case R.id.add: { horiz.incrementProgressBy(10); 点击一次 增加10进度 horiz.incrementSecondaryProgressBy(10); break; } case R.id.jianshao: { horiz.incrementProgressBy(-10); 点击一次 减少10进度 horiz.incrementSecondaryProgressBy(-10); break; }添加一个Button 来显示 进度条对话框
case R.id.show: { ProgressDialog dialog=new ProgressDialog(this); new 一个进度条对话框实例 dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 显示一个 横向的进度条 对话框 dialog.setTitle("慕课网"); 添加标题信息 dialog.setMax(100); 添加最大值 dialog.incrementProgressBy(50);设置当前进度 会自动算出百分比值dialog.setIndeterminate(false); 设置 是否要 明确的 进度值 设置为false 就是 显示 精确的 进度设置为true 就是不明确进度值 就会一直在那 走啊走 dialog.setIcon(R.mipmap.ic_launcher); 添加图标 dialog.setMessage("欢迎来到慕课网");添加内容信息 dialog.setButton(ProgressDialog.BUTTON_POSITIVE, "确定", new DialogInterface.OnClickListener() { @Override 添加一个 确定按钮, 绑定单击事件监听器 public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, "你好慕课网", Toast.LENGTH_SHORT).show(); } }); dialog.show(); 最后不要忘了 一定要 show一下 显示出来 dialog.setCancelable(true); 设置为true break;}