多式样ProgressBar

来源:互联网 发布:淘宝网泳衣专卖店 编辑:程序博客网 时间:2024/05/01 12:02

多式样ProgressBar

普通圆形ProgressBar






该类型进度条也就是一个表示运转的过程,例如发送短信,连接网络等等,表示一个过程正在执行中。

一般只要在XML布局中定义就可以了。

  1. <progressBar android:id="@+id/widget43"
  2.       android:layout_width="wrap_content"
  3.       android:layout_height="wrap_content"   
  4.       android:layout_gravity="center_vertical">
  5. </ProgressBar>
复制代码

此时,没有设置它的风格,那么它就是圆形的,一直会旋转的进度条。

各大小样式圆形ProgressBar


超大号圆形ProgressBar


此时,给设置一个style风格属性后,该ProgressBar就有了一个风格,这里大号ProgressBar的风格是:

  1. style="?android:attr/progressBarStyleLarge"
复制代码

完整XML定义是:

  1. <progressBar android:id="@+id/widget196"
  2.       android:layout_width="wrap_content"
  3.       android:layout_height="wrap_content"
  4.       style="?android:attr/progressBarStyleLarge">
  5. </ProgressBar>



小号圆形ProgressBar




小号ProgressBar对应的风格是:

  1. style="?android:attr/progressBarStyleSmall"

完整XML定义是:

  1. <progressBar android:id="@+id/widget108"
  2.       android:layout_width="wrap_content"
  3.       android:layout_height="wrap_content"
  4.       style="?android:attr/progressBarStyleSmall">
  5. </ProgressBar>



标题型圆形ProgressBar






标题型ProgressBar对应的风格是:

  1. style="?android:attr/progressBarStyleSmallTitle"

完整XML定义是:

  1. <progressBar android:id="@+id/widget110"
  2.     android:layout_width="wrap_content"
  3.     android:layout_height="wrap_content"
  4.     style="?android:attr/progressBarStyleSmallTitle">
  5. </ProgressBar>

代码中实现:

  1. @Override
  2.     protected void onCreate(Bundle savedInstanceState) {
  3.         // TODO Auto-generated method stub
  4.         super.onCreate(savedInstanceState);
  5.         requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
  6.         //请求窗口特色风格,这里设置成不明确的进度风格
  7.         setContentView(R.layout.second);
  8.         setProgressBarIndeterminateVisibility(true);
  9.         //设置标题栏中的不明确的进度条是否可以显示
  10.     }


长形进度条


布局中的长形进度条


①首先在XML进行布局
  1. <progressBar android:id="@+id/progressbar_updown"
  2.         android:layout_width="200dp"
  3.         android:layout_height="wrap_content"
  4.         style="?android:attr/progressBarStyleHorizontal"
  5.         android:layout_gravity="center_vertical"
  6.         android:max="100"
  7.         android:progress="50"
  8.         android:secondaryProgress="70"    >

讲解:

style="?android:attr/progressBarStyleHorizontal"   设置风格为长形 android:max="100"   最大进度值为100android:progress="50"  初始化的进度值android:secondaryProgress="70" 初始化的底层第二个进度值 android:layout_gravity="center_vertical"   垂直居中



②代码中运用

  1. private ProgressBar myProgressBar;
  2. //定义ProgressBar
  3. myProgressBar = (ProgressBar) findViewById(R.id.progressbar_updown);
  4. //ProgressBar通过ID来从XML中获取
  5. myProgressBar.incrementProgressBy(5);
  6. //ProgressBar进度值增加5
  7. myProgressBar.incrementProgressBy(-5);
  8. //ProgressBar进度值减少5
  9. myProgressBar.incrementSecondaryProgressBy(5);
  10. //ProgressBar背后的第二个进度条 进度值增加5
  11. myProgressBar.incrementSecondaryProgressBy(-5);
  12. //ProgressBar背后的第二个进度条 进度值减少5




页面标题中的长形进度条



代码实现:
①先设置一下窗口风格特性

  1. requestWindowFeature(Window.FEATURE_PROGRESS);
  2. //请求一个窗口进度条特性风格
  3. setContentView(R.layout.main);
  4. setProgressBarVisibility(true);
  5. //设置进度条可视

②然后设置进度值

  1. setProgress(myProgressBar.getProgress() * 100);
  2. //设置标题栏中前景的一个进度条进度值
  3. setSecondaryProgress(myProgressBar.getSecondaryProgress() * 100);
  4. //设置标题栏中后面的一个进度条进度值
  5. //ProgressBar.getSecondaryProgress() 是用来获取其他进度条的进度值
0 0
原创粉丝点击