原文章地址 https://liuzhichao.com/p/636.html
進(jìn)度條默認(rèn)是不確定(indeterminate=true)Android進(jìn)度條
Android進(jìn)度條有4種風(fēng)格可以使用。
默認(rèn)值是progressBarStyle资铡。
設(shè)置成progressBarStyleSmall后,圖標(biāo)變小。
設(shè)置成progressBarStyleLarge后,圖標(biāo)變大
設(shè)置成progressBarStyleHorizontal后,變成橫向長方形。
自定義圓形進(jìn)度條ProgressBar的一般有三種方式:
一、通過動畫實(shí)現(xiàn)
定義res/anim/loading_anim.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<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>`
在layout文件中引用如下:
<ProgressBar
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" />
二南蹂、通過自定義顏色實(shí)現(xiàn)
定義res/drawable/loading_color.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" >
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="8"
android:useLevel="false" >
<gradient
android:centerColor="#FFDC35"
android:centerY="0.50"
android:endColor="#CE0000"
android:startColor="#FFFFFF"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>
在layout文件中引用如下:
<ProgressBar
android:id="@+id/progressBar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="false"
android:indeterminateDrawable="@drawable/loading_color" />
三、使用一張圖片進(jìn)行自定義
定義res/drawable/loading_img.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<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>
在layout文件中引用如下:
<ProgressBar
android:id="@+id/progressBar3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="false"
android:indeterminateDrawable="@drawable/lodaing_img"/>