如何在圆内画圆弧?

How to draw a circular stroke inside a circle?

我正在尝试实现这种效果,但是我无法在圆圈内画出白色的圆形描边。在我的实现中,白色描边出现在圆圈外

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="oval">
            <corners android:radius="10dip" />

            <stroke
                android:width="5dip"
                android:color="#ffffff" />
            <solid android:color="#f50000" />
        </shape>

    </item>

</layer-list>

预期输出:-

给你。只需稍微修改您的文件以包含两个项目并在第二个项目上添加一个填充。 希望对您有所帮助:

<?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="#f50000" />
        </shape>
    </item>
    <item
        android:left="2dp"
        android:right="2dp"
        android:top="2dp"
        android:bottom="2dp">
        <shape
            android:shape="oval">
            <stroke
                android:width="2dp"
                android:color="#ffffff" />
        </shape>
    </item>
</layer-list>

你需要这样的xml(优化):

<?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="#007" />
    </shape>
</item>
<item
    android:left="2dp"
    android:right="2dp"
    android:top="2dp"
    android:bottom="2dp">
    <shape
        android:shape="oval">
        <stroke
            android:width="1dp"
            android:color="#f00" />
        <size
            android:width="25dp"
            android:height="25dp" />
    </shape>
</item>
</layer-list>

或xml像这样(未优化):

<?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="#007" />
        <size
            android:width="25dp"
            android:height="25dp" />
    </shape>
</item>
<item>
    <shape android:shape="oval">
        <stroke
            android:width="8dp"
            android:color="@android:color/transparent" />
        <solid android:color="#f00" />
        <size
            android:width="45dp"
            android:height="45dp" />
    </shape>
</item>
<item>
    <shape android:shape="oval">
        <stroke
            android:width="10dp"
            android:color="@android:color/transparent" />
        <solid android:color="#007" />
        <size
            android:width="10dp"
            android:height="10dp" />
    </shape>
</item>
</layer-list>

对于这个结果:

我使用 <layer-list><inset> 椭圆形完成了此操作:

<?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="#f50000"/>
        </shape>
    </item>

    <item>
        <inset
            android:insetTop="5dp"
            android:insetLeft="5dp"
            android:insetRight="5dp"
            android:insetBottom="5dp">
            <shape android:shape="oval">
                <stroke
                    android:color="#fff"
                    android:width="5dp"/>
            </shape>
        </inset>
    </item>
</layer-list>

您可以通过更改第二项中的值来控制插入量和笔画宽度