Android 3种自定义圆形ProgressBar

一. 图片自定义圆形
首先在drawable目录定义背景xml res/drawable/loading_img.xml


<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<rotate
android:drawable="@drawable/exchange_loading"
android:fromDegrees="0.0"
android:pivotX="50.0%"
android:pivotY="50.0%"
android:toDegrees="360.0" />
item>
layer-list>

然后在布局进行引用

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

二.通过自定义颜色实现,跟图片差不多
1.定义res/drawable/loading_color.xml如下

"1.0" encoding="utf-8"?>
"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" />

2.在布局文件引用

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

三.通过一系列图片进行变换,类似于帧动画
1.定义res/anim/loading_anim.xml如下


<animation-list android:oneshot="false"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:duration="150" android:drawable="@drawable/loading_blue_16_f0" />
<item android:duration="150" android:drawable="@drawable/loading_blue_16_f1" />
<item android:duration="150" android:drawable="@drawable/loading_blue_16_f2" />
<item android:duration="150" android:drawable="@drawable/loading_blue_16_f3" />
<item android:duration="150" android:drawable="@drawable/loading_blue_16_f4" />
<item android:duration="150" android:drawable="@drawable/loading_blue_16_f5" />
<item android:duration="150" android:drawable="@drawable/loading_blue_16_f6" />
<item android:duration="150" android:drawable="@drawable/loading_blue_16_f7" />
<item android:duration="150" android:drawable="@drawable/loading_blue_16_f8" />
<item android:duration="150" android:drawable="@drawable/loading_blue_16_f9" />
<item android:duration="150" android:drawable="@drawable/loading_blue_16_f10" />
<item android:duration="150" android:drawable="@drawable/loading_blue_16_f11" />
<item android:duration="150" android:drawable="@drawable/loading_blue_16_f12" />
<item android:duration="150" android:drawable="@drawable/loading_blue_16_f13" />
<item android:duration="150" android:drawable="@drawable/loading_blue_16_f14" />
<item android:duration="150" android:drawable="@drawable/loading_blue_16_f15" />
<item android:duration="150" android:drawable="@drawable/loading_blue_16_f16" />
<item android:duration="150" android:drawable="@drawable/loading_blue_16_f17" />
animation-list>

2.也是在布局文件中引用

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" />

你可能感兴趣的:(安卓)