ProgressBar圆形进度

一、概述

ProgressBar 的圆形进度很容易实现,但是不经常用的话,时间一长容易忘记,到用的时候,又要百度一番,到处找。

这里记录一下,方便日后使用。

效果图,外面的圆环就是ProgressBar:
在这里插入图片描述

二、代码

布局

 <ProgressBar
        android:id="@+id/recordProgressBar"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_gravity="bottom|center_horizontal"
        android:layout_marginBottom="120dp"
        android:indeterminate="false"
        android:indeterminateOnly="false"
        android:progressDrawable="@drawable/record_progress_drawable" />

indeterminate必须为false,表示确定的进度

progressDrawable

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape android:shape="ring" android:useLevel="false">
            <solid
                android:width="10dp"
                android:color="#f2f2f2" />
        </shape>
    </item>

    <item android:id="@android:id/progress">
        <shape android:shape="ring">
            <solid
                android:width="10dp"
                android:color="#ff0000" />

        </shape>
    </item>

</layer-list>

两个id很重要,要指定android:id/background 和 android:id/progress。
shape 都设置为ring ,background的shape要设置useLevel为false,progress的shape 不需要设置。
代码中只要 setProgress 即可。

猜你喜欢

转载自blog.csdn.net/ganduwei/article/details/129781408
今日推荐