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 即可。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值