首页 > 解决方案 > 如何制作一个实心圆形进度条?(不使用外部库)

问题描述

我想在 Android Studio 中制作一个圆形填充进度条。我的目标是实现这样的目标;

示例图片

例如,第一张图像的进度值为 100,然后每隔一秒就会有一点圆圈消失,直到什么也没有。

我试过这个,但我无法让我的存储库工作,因此我正在寻找一种更“非外部”的方式来做到这一点。

标签: androidxmlandroid-studioprogress-barandroid-progressbar

解决方案


借助Material Components 库,您可以使用官方的CircularProgressIndicator.
就像是:

<com.google.android.material.progressindicator.CircularProgressIndicator
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:trackThickness="20dp"    
                />

在此处输入图像描述

如果您使用的是jetpack Compose,您可以使用CircularProgressIndicator

CircularProgressIndicator(
    strokeWidth = 20.dp, 
    progress = animatedProgress.value)

在此处输入图像描述


推荐阅读