我正在尝试创建一个如下所示的自定义进度对话框:
现在我看到有这样的帖子:How to Customize a Progress Bar In Android
这非常适合创建简单的自定义对话框。但是,在尝试扩展其示例以将蓝点附加到进度对话框自定义可绘制对象的末尾时,我遇到了麻烦。
如何实现此效果?
对于带拇指的进度条,您可以使用SeekArc
。请参考下面的SeekArc
链接>
https://github.com/neild001/SeekArc
如果您只需要没有拇指的自定义进度条,则可以使用以下代码。
使用下面的代码,您可以创建没有拇指的自定义圆形进度条:
在布局文件中:
<ProgressBar android:layout_width="300dp" android:layout_height="300dp" style="?android:attr/progressBarStyleHorizontal" android:progressDrawable="@drawable/custom_progressbar" android:background="@drawable/custom_progressbar" android:max="100" android:progress="70" android:rotation="180" android:layout_centerInParent="true"/>
在Drawable文件中:custom_progressbar.xml
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="270" android:toDegrees="270"> <shape android:innerRadiusRatio="2.5" android:shape="ring" android:thickness="2dp" android:useLevel="true"><!-- this line fixes the issue for lollipop api 21 --> <gradient android:angle="0" android:endColor="@android:color/white" android:startColor="@android:color/white" android:type="sweep" android:useLevel="false" /> </shape> </rotate>
以上代码的输出是: