简单的自定义圆形进度条ProgressBar
今天做下拉刷新的时候用到了ProgressBar(之后博客会更新下拉刷新的内容),发现真的丑到爆 so…… 自定义了一个 比较简单的写法:
<ProgressBar
android:id="@+id/pb_circle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateDrawable="@drawable/custom_progress"
/>
<?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="16dp"
android:shape="ring"
android:thickness="3dp"
android:useLevel="false"
>
<gradient
android:centerColor="#3f00"
android:endColor="#f00"
android:startColor="#fff"
/>
</shape>
</rotate>
简单解释一下:
Progress的indeterminateDrawable 设置drawable对象
写一个custom_progress.xml文件
shape绘制一个圆环: shape = “ring”
半径: innerRadius
圆环“厚度” thickness (大圆半径 - 小圆半径)
gradient 设置渐变色
在shape外套一个roate动画 这样就实现了圆形进度条的旋转啦
这个自定义的比较简单,大家可以自己发挥,做出更好看的来