XML Drawable 在我的透明环形中间创建了一条意外的线

XML Drawable creates an unintended line in the middle of my transparent ring shape

我正在尝试使用 xml 中的环形在 xml 中创建一个空心圆。然而,我最终得到一条线,似乎展示了圆的半径,从圆环的中间开始向右移动。

xml 我想要实现的形状的代码:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
android:shape="ring"
android:thicknessRatio="2"
android:useLevel="false">

<solid android:color="@android:color/transparent"/>

<stroke
    android:width="5dp"
    android:color="#FFFFFF"/>

<size
    android:width="75dp"
    android:height="75dp"/>
</shape>

同样,问题是我得到了一条清晰明了的线,从形状的中间开始,一直到我所拥有的空心圆的边缘,透明度有效,但我不知道是什么原因造成的中间的线。感谢任何帮助。

只需将 shape="ring" 替换为 shape="oval"

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
android:shape="oval"
android:thicknessRatio="2"
android:useLevel="false">

<solid android:color="@android:color/transparent"/>

<stroke
    android:width="5dp"
    android:color="#FFFFFF"/>

<size
    android:width="75dp"
    android:height="75dp"/>
</shape>

您可以使用 android:shape="oval" 代替 android:shape="ring"

您可以使用环形,但您应该使用 solid 而不是 stroke。您可以尝试 android:innerRadiusandroid:thicknessRatio,直到形状看起来像您想要的那样。

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:innerRadius="10dp"
    android:shape="ring"
    android:thicknessRatio="10"
    android:useLevel="false">

    <solid android:color="@android:color/holo_red_dark"/>

    <size
        android:width="75dp"
        android:height="75dp"/>
</shape>

stroke 在环上看起来很奇怪,因为形状创建为一个区域,其边缘由不间断的路径描述。纯色用于填充区域,描边颜色用于边缘。