1.使用progressbar组件创建进度条
android:max 用于设置进度条最大值
android:progress 用于设置进度条以完成的进度
android:progressDrawable 用于设置进度条轨道的绘制形式
setprogress()方法:用于设置进度完成百分比
incrementprogressby()方法:用于设置进度条的进度增加或减少

?android:attr/progressBarStyleHorizontal 细水平长条进度条
?android:attr/progressBarStyleLarge 大圆形进度条
?android:attr/progressBarStyleSmall 小圆形进度条
@android:style/Widget.ProgressBar.Large 大跳跃、旋转画面的进度条
@android:style/Widget.ProgressBar.Small 小跳跃、旋转画面的进度条
@android:style/Widget.ProgressBar.Horpzontal 粗水平长度进度条

布局代码:
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleLarge"/>

<ProgressBar
android:id="@+id/progressBar2"
style="?android:attr/progressBarStyleHorizontal"
android:max="100"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<ProgressBar
android:id="@+id/progressBar3"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<ProgressBar
android:id="@+id/progressBar4"
style="@android:style/Widget.ProgressBar.Large"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<ProgressBar
android:id="@+id/progressBar5"
style="@android:style/Widget.ProgressBar.Small"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<ProgressBar
android:id="@+id/progressBar6"
style="@android:style/Widget.ProgressBar.Horizontal"
android:max="100"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

实例化Handler类的对象,重写handleMessage()方法:
horizonP=(ProgressBar)findViewById(R.id.progressBar2);
circleP=(ProgressBar)findViewById(R.id.progressBar1);
mHandler=new Handler(){

@Override
public void handleMessage(Message msg) {
if (msg.what==0x111) {
horizonP.setProgress(mProgressStatus);
circleP.setProgress(mProgressStatus);
}else {
Toast.makeText(MainActivity.this, "耗时操作已完成", Toast.LENGTH_SHORT).show();
horizonP.setVisibility(View.GONE);
circleP.setVisibility(View.GONE);
}
}
开启一个线程,用于模拟一个好事操作:
new Thread(new Runnable() {

@Override
public void run() {
while (true) {
mProgressStatus = doWork();
Message m = new Message();
if (mProgressStatus<100) {
m.what=0x111;
mHandler.sendMessage(m);
}else {
m.what=0x110;
mHandler.sendMessage(m);
break;
}
}
}

private int doWork() {
mProgressStatus+=Math.random()*10;
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return mProgressStatus;
}
}).start();


更多相关文章

  1. Android横竖屏切换小结
  2. android TextView selector点击样式改变
  3. Android(安卓)ProgressBar控件理解
  4. android 设置布局动画
  5. Android(安卓)TextView全属性
  6. android ListView 示例1 entries 指定一个数组资源
  7. android 常用布局有哪些
  8. Android(安卓)TextView多行文本滚动实现
  9. Android(安卓)状态栏全透明策略

随机推荐

  1. Android 判断应用是否开启了通知权限
  2. Android图形架构分析总结
  3. Ionic开发遇到的问题和解决方法
  4. 在AndroidManifest.xml文件中的android:w
  5. Android 5.0 SystemUI 视图框架
  6. Android实现MVVM+LiveData+Retrofit
  7. android图片资源转换
  8. 安卓历代版本
  9. Android_SearchView
  10. 【Android Developers Training】 12. 支