自定义旋转的ProgressBar

来源:互联网 发布:独立开发者 知乎 编辑:程序博客网 时间:2024/06/09 15:24

在drawable目录下新建custom_progress.xml文件

<?xml version="1.0" encoding="utf-8"?><rotatexmlns:android="http://schemas.android.com/apk/res/android"    android:fromDegrees="0"    android:pivotX="50%"    android:pivotY="50%"    android:toDegrees="360" >    <shape        android:innerRadius="12dp"        android:shape="ring"        android:thickness="3dp"        android:useLevel="false" >        <gradient            android:centerColor="#3f00"            android:endColor="#f00"            android:startColor="#fff" />    </shape></rotate>

属性的解释:

<?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="12p"//圆环的内部半径        android:shape="ring"//圆环        android:thickness="3dp"//圆环的厚度        android:useLevel="false"//将ProgressBar的原有动画禁掉         >        <gradient//渐变            android:centerColor="#3f00"//中间颜色            android:endColor="#f00"            android:startColor="#fff" />    </shape></rotate>

将以上的drawable文件设置在ProgressBar的indeterminateDrawable属性中

<ProgressBar            android:id="@+id/pb_progress"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_gravity="center"            android:indeterminateDrawable="@drawable/custom_progress" />
0 0
原创粉丝点击