在drawable目录下自定义一个shape的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:innerRadius="15dp"
android:shape="ring"
android:thickness="3dp"
android:useLevel="false" >
<gradient
android:centerColor="#5f00"
android:endColor="#f00"
android:startColor="#fff"
android:type="sweep" />
</shape>
</rotate>
在最外层包裹了一个rotate,让内层的shape旋转即可实现进度条在转。rotate标签里设置旋转的起始和终止角度,相对自身中间。shape标签里设置形状为圆环,内径,厚度。渐变标签里设置起始和中间、终止的颜色。即可实现如下的进度条在不停地旋转。然后在progressbar控件里加入属性:android:indeterminateDrawable="@drawable/shape_custom_progress"