最近总结了一下ProgressBar控件,参考了许多人的博客,在此一并感谢


Android支持的几种风格的进度条:

不设置 style 表现形式为默认的中型大小的进度条(普通性的进度条)

style="@android:style/Widget.ProgressBar.Inverse"   普通大小进度条(反向的)

style="@android:style/Widget.ProgressBar.Large"  大进度条

style="@android:style/Widget.ProgressBar.Large.Inverse" 大进度条(反向的)

style="@android:style/Widget.ProgressBar.Small"  小进度条

style="@android:style/Widget.ProgressBar.Small.Inverse"  小进度条(反向的)

style="@android:style/Widget.ProgressBar.Horizontal"     水平进度条

前六个进度条的样式为 圆圈 样式的,分为 正向转 和 反向转 两种
最后一种为水平进度条

在 SDK 中  sdk\platforms\android-7\data\res\values\styles.xml 文件下,系统提供的集中 ProgressBar 样式

   

   
   
   

   

   

   
   
   

   

    progress_indeterminate_horizonta.xml中的内容

           xmlns:android="http://schemas.android.com/apk/res/android"
         android:oneshot="false">
    
    
    
 

以上的style为系统提供的默认进度条的样式。
ProgressBar   该控件默认的样式为圆形进度条,Widget.ProgressBar中android:indeterminateOnly默认设置为true
indeterminate意思是“模糊的,不明确的”
Widget.ProgressBar   在sytle样式文件中android:indeterminateOnly属性设置为true,表示的是这个ProgressBar是模糊的,不明确的
 当前它并没有体现出具体的进度,只是一个小圆圈在转,在系统默认的 style 中android:indeterminateOnly设置为true
Widget.ProgressBar.Horizontal    在sytle样式文件中android:indeterminateOnly属性置为false
 如果需要使用android:indeterminateDrawable属性来自定义进度条,则在xml布局文件中需要将android:indeterminateOnly设置为true
 则出现一个默认的加载的动画,即android:indeterminateDrawable中设置的

在 xml 布局文件中使用 ProgressBar ,其中第一个显示的是圆圈样式的进度条,第二个显示的是 系统提供样式的 水平进度条。

//圆形进度条         
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:id="@+id/progress_bar">


            
//水平进度条
      android:id="@+id/progress_horizontal"       
      style="?android:attr/progressBarStyleHorizontal"
      android:layout_width="200dip"
      android:layout_height="wrap_content"
      android:max="100"
      android:progress="50"
      android:secondaryProgress="75">

==================================================================================================

    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context=".MainActivity"
    android:background="#ffffff" >
   
   
            android:id="@+id/pb_circle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dip"
        android:layout_centerHorizontal="true"
        />

   
            android:id="@+id/pb_horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/pb_circle"
        android:layout_marginTop="30dip"
        style="?android:attr/progressBarStyleHorizontal"
        android:progress="50"
        android:secondaryProgress="60"
        android:minWidth="200dip"
        android:indeterminateOnly="true"
        />
   

Android 进度条 的属性说明:

android:animationResolution 
android:indeterminate 
android:indeterminateBehavior 
android:indeterminateDrawable  设置了动画中显示的图片 或 这动画的xml文件  
android:indeterminateDuration  设置不精确显示进度的持续时间
android:indeterminateOnly  该属性设置为true,则进度条将忽略进度,进而呈现一个无限循环的动画

android:interpolator   
android:max  设置进度条的最大值(最后一个水平进度条的设置为1000)
android:maxHeight  
android:maxWidth 
android:minHeight   
android:minWidth   
android:mirrorForRtl 
android:progress  设置当前的进度(最后一个水平进度条设置当前进度为500)
android:progressDrawable  设置进度的drawable参数,通过这个属性页可以自定不同样式的进度条
android:secondaryProgress  设置第二进度条(用于显示进度条里面的第二层进度条)

// english
android:animationResolution  Timeout between frames of animation in milliseconds
 Must be an integer value, such as "100".
android:indeterminate  Allows to enable the indeterminate mode. 
android:indeterminateBehavior  Defines how the indeterminate mode should behave when the progress reaches max. 
android:indeterminateDrawable  Drawable used for the indeterminate mode. 
android:indeterminateDuration  Duration of the indeterminate animation. 
android:indeterminateOnly  Restricts to ONLY indeterminate mode (state-keeping progress mode will not work). 

android:interpolator   
android:max  Defines the maximum value the progress can take. 
android:maxHeight  An optional argument to supply a maximum height for this view. 
android:maxWidth  An optional argument to supply a maximum width for this view. 
android:minHeight   
android:minWidth   
android:mirrorForRtl  Defines if the associated drawables need to be mirrored when in RTL mode. 
android:progress  Defines the default progress value, between 0 and max. 
android:progressDrawable  Drawable used for the progress mode. 
android:secondaryProgress  Defines the secondary progress value, between 0 and max. 


// 自定义进度条的流程
1、圆形进度条
首先,需要在 xml 中自定义一个动画,用于替换掉style中默认的android:indeterminateDrawable
res/drawable/circle.xml 中:
    android:drawable="@drawable/circle_progress" 
    android:pivotX="50%" 
    android:pivotY="50%" 
/> 
circle_progress 为自定义的圆形进度条的图片资源


然后,在 xml 布局文件中:
 android:id="@+id/circle" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:layout_centerHorizontal="true" 
 android:indeterminateDrawable="@drawable/circle" 
/> 

2、水平进度条
首先,需要在 xml 中自定义一个动画
res/drawable/horizontal.xml 中:
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:oneshot="false">
   
   
   

progressbar_indeterminate1,progressbar_indeterminate2,progressbar_indeterminate3 为自定义的水平进度条的图片资源

然后,在 xml 布局文件中:
        android:id="@+id/pb_horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="50dip"
        android:layout_marginRight="50dip"
        android:layout_centerHorizontal="true"
        style="?android:attr/progressBarStyleHorizontal"
        android:progressDrawable="@drawable/horizontal"
        android:indeterminateDrawable="@drawable/horizontal"
/>

更多相关文章

  1. android TextView selector点击样式改变
  2. Android LinearLayout中实现水平方向控件居右
  3. 【Android 应用开发】Android资源文件 - 使用资源存储字符串 颜
  4. android 布局文件属性说明
  5. Android 属性文件build.prop,获取属性以及设置属性
  6. Android获取打开各种文件Intent汇总
  7. Android 使用PdfDocument生成PDF文件及遇到的问题

随机推荐

  1. android自定义ListView背景
  2. Android图形图像使用总结
  3. 【笔记】VisionMobile:扁平、扩展、挖掘,Go
  4. Android(安卓)Butterknife 框架源码解析(2
  5. Android(安卓)解决hellocharts与ViewPage
  6. Android一个页码的导航条
  7. 2012-04-10 16:32 android与WEB服务器交
  8. Android(安卓)UI之ImageView
  9. Android平台上神器Tasker的教程和其他参
  10. Android开发学习资源