Android自定义ProgressBar样式(Shape实现转动的圆环)
阿里云国内75折 回扣 微信号:monov8 |
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6 |
最终效果
第一步在drawable文件夹下新建一个xml文件叫progressbar_shape.xml代码如下
progressbar_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%">
<shape
android:shape="ring"
android:innerRadiusRatio="4"
android:thicknessRatio="10"
android:useLevel="false">
<gradient
android:startColor="#FF5722"
android:centerColor="#FFEB3B"
android:type="sweep"
android:useLevel="false"
android:centerY="0.50"
android:endColor="#9C27B0" />
</shape>
</animated-rotate>
第二步在ProgressBar中使用indeterminateDrawable属性引用上面的xml文件
你布局里的ProgressBar
<ProgressBar
android:id="@+id/progress"
android:visibility="visible"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_margin="30dp"
android:indeterminateDrawable="@drawable/progressbar_shape" />