自定义圆形进度条ProgressBar的三种方式

进度条默认是不确定(indeterminate=true)Android进度条

Android进度条有4种风格可以使用。

默认值是progressBarStyle。
设置成progressBarStyleSmall后,图标变小。
设置成progressBarStyleLarge后,图标变大
设置成progressBarStyleHorizontal后,变成横向长方形。

自定义圆形进度条ProgressBar的一般有三种方式:

一、通过动画实现

定义res/anim/loading_anim.xml如下:

xml version="1.0" encoding="utf-8"?>
 android:oneshot="false"
  xmlns:android="http://schemas.android.com/apk/res/android">
   android:duration="150" android:drawable="@drawable/loading_blue_16_f0" />
   android:duration="150" android:drawable="@drawable/loading_blue_16_f1" />
   android:duration="150" android:drawable="@drawable/loading_blue_16_f2" />
   android:duration="150" android:drawable="@drawable/loading_blue_16_f3" />
   android:duration="150" android:drawable="@drawable/loading_blue_16_f4" />
   android:duration="150" android:drawable="@drawable/loading_blue_16_f5" />
   android:duration="150" android:drawable="@drawable/loading_blue_16_f6" />
   android:duration="150" android:drawable="@drawable/loading_blue_16_f7" />
   android:duration="150" android:drawable="@drawable/loading_blue_16_f8" />
   android:duration="150" android:drawable="@drawable/loading_blue_16_f9" />
   android:duration="150" android:drawable="@drawable/loading_blue_16_f10" />
   android:duration="150" android:drawable="@drawable/loading_blue_16_f11" />
   android:duration="150" android:drawable="@drawable/loading_blue_16_f12" />
   android:duration="150" android:drawable="@drawable/loading_blue_16_f13" />
   android:duration="150" android:drawable="@drawable/loading_blue_16_f14" />
   android:duration="150" android:drawable="@drawable/loading_blue_16_f15" />
   android:duration="150" android:drawable="@drawable/loading_blue_16_f16" />
   android:duration="150" android:drawable="@drawable/loading_blue_16_f17" />

在layout文件中引用如下:


        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="20dip"
        android:layout_marginTop="20dip"
        android:indeterminate="false"
        android:indeterminateDrawable="@anim/loading_anim" />

二、通过自定义颜色实现

定义res/drawable/loading_color.xml如下:

xml version="1.0" encoding="utf-8"?>
 xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360" >
    
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:thicknessRatio="8"
        android:useLevel="false" >
        
            android:centerColor="#FFDC35"
            android:centerY="0.50"
            android:endColor="#CE0000"
            android:startColor="#FFFFFF"
            android:type="sweep"
            android:useLevel="false" />
    

在layout文件中引用如下:


        android:id="@+id/progressBar2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminate="false" 
        android:indeterminateDrawable="@drawable/loading_color" />

三、使用一张图片进行自定义

定义res/drawable/loading_img.xml如下:

xml version="1.0" encoding="utf-8"?>
 xmlns:android="http://schemas.android.com/apk/res/android" >
    
        
            android:drawable="@drawable/exchange_loading"
            android:fromDegrees="0.0"
            android:pivotX="50.0%"
            android:pivotY="50.0%"
            android:toDegrees="360.0" />
    

在layout文件中引用如下:

    
        android:id="@+id/progressBar3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminate="false"
        android:indeterminateDrawable="@drawable/lodaing_img"
        />

ProgressBar


转自:http://liuzhichao.com/p/636.html

你可能感兴趣的:(Android)