一、概述
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 即可。
这篇文章记录了如何在Android中创建一个圆形的ProgressBar,包括必要的布局代码和progressDrawable设置。关键点在于设置indeterminate为false和指定background及progress的id,颜色和形状。通过设置shape为ring和调整solid宽度可以定制进度条的样式。



3676

被折叠的 条评论
为什么被折叠?



