使用Shape實(shí)現(xiàn)樣式
使用Shape中的ring
實(shí)現(xiàn)颊郎,如下布局ring.xml
:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:thickness="5dp"
android:useLevel="false" >
<gradient
android:endColor="#888"
android:startColor="#ccc"
android:type="sweep"
android:useLevel="false" />
</shape>
使用rotate
使之旋轉(zhuǎn)
如下progressbar.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<rotate
android:drawable="@drawable/ring"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="1080"/>
</item>
</layer-list>
注意:其中fromDegrees與toDegrees之差要是360的倍數(shù),不然中間會(huì)有轉(zhuǎn)的時(shí)候會(huì)跳一下骚烧,另外没龙,這個(gè)差越大就轉(zhuǎn)得越快漓摩,具體效果大家可以自行試一下
使用
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateDrawable="@drawable/progressbar" <!-- 這里使用自定義的progressbar樣式 -->
/>
更簡單的方法
直接使用一個(gè)布局文件就可以實(shí)現(xiàn):
<?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="1080" >
<shape
android:shape="ring"
android:thickness="5dp"
android:useLevel="false" >
<gradient
android:endColor="#888"
android:startColor="#ccc"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>