您的位置:首页 > 其它

自定义旋转的ProgressBar

2016-01-31 09:07 393 查看
在drawable目录下新建custom_progress.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="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" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: