安卓智慧上海学习笔记系列——自定义圆环进度条

来源:互联网 发布:淘宝买家好评率怎么看 编辑:程序博客网 时间:2024/05/06 10:23

在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" 


0 0
原创粉丝点击