我有一个进度条,但在运行Android Lollipop的设备上无法正常工作。
在M上的截图:
在Lollipop上的截图:
文件名:circle_percentage_drawable.xml
在M上的截图:
![enter image description here](https://istack.dev59.com/WP1wP.webp)
![enter image description here](https://istack.dev59.com/gJg8Q.webp)
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/colorTranslucentBlack"/>
</shape>
</item>
<item android:id="@android:id/progress">
<rotate
android:fromDegrees="270"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="270">
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thicknessRatio="25.0">
<gradient
android:centerColor="@android:color/holo_red_dark"
android:endColor="@android:color/holo_red_dark"
android:startColor="@android:color/holo_red_dark"
android:type="sweep"/>
</shape>
</rotate>
</item>
<item android:id="@android:id/secondaryProgress">
<rotate
android:fromDegrees="270"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="270">
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thicknessRatio="25.0">
<gradient
android:centerColor="@android:color/holo_red_dark"
android:endColor="@android:color/holo_red_dark"
android:startColor="@android:color/holo_red_dark"
android:type="sweep"/>
</shape>
</rotate>
</item>
</layer-list>
这个可绘制对象被用作ProgressView的背景,如下所示:
<ProgressBar
android:id="@+id/circle_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="70dp"
android:layout_height="70dp"
android:gravity="center"
android:progress="65"
android:indeterminate="false"
android:progressDrawable="@drawable/circle_percentage_drawable"
/>
当在运行Android M,KitKat和Jellybean版本的设备上绘制一个半径为65%的圆时,它将被渲染成一个圆。然而,如果在运行Android Lollipop (API 21)的设备上运行相同的代码,则该圆将显示为100%。
完整源代码可在此处找到:https://github.com/slashrootv200/CircleProgressPercentage
android:useLevel=true
。 - Ahsan Kamal