问题描述
我有一个进度绘图,在运行Android Lollipop的设备上无法正常工作.
I have a progress drawable which does not work properly on devices running Android Lollipop.
M上的屏幕截图
棒棒糖上的屏幕截图
Screenshot on Lollipop
<?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%.
The renders as a circle drawn to 65% show up on devices running Android M, KitKat, Jellybean. However, if the same code is run on Android Lollipop (API 21) the circle shows as 100%.
此处提供完整的源代码: https://github.com/slashrootv200/CircleProgressPercentage
Full source code available here: https://github.com/slashrootv200/CircleProgressPercentage
推荐答案
在循环进度条xml中添加android:useLevel=true"
Add android:useLevel=true"
in your circular progressbar xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval"
android:useLevel="true">
<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"
android:useLevel="true">
<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"
android:useLevel="true">
<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>
这篇关于自定义进度可绘制在Android Lollipop(API 21)设备上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!