如何创建内部路径透明的矢量可绘制对象?

How to create a vector drawable with inner path transparent?

我正在尝试创建一个喜欢的图标,类似于下面的图标。

在创建它时,我需要内部路径(蓝色区域)在 result.But 中透明,同时提供透明颜色,它显示在外部填充的颜色 path.i.e 橙色的完整形状。我怎样才能用透明的内部路径制作一个可绘制的矢量

我的矢量图是

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="72dp"
        android:height="66dp"
        android:viewportHeight="66"
        android:viewportWidth="72">

    <path
        android:fillColor="@android:color/transparent"
        android:pathData="M 0.00 0.00 L 72.00 0.00 L 72.00 66.00 L 0.00 66.00 L 0.00 0.00 Z" />
    <path
        android:fillColor="#F7592B"
        android:pathData="M 20.99 1.04 C 26.30 1.45 30.97 4.88 36.04 5.70 C 40.02 5.23 43.79 2.79 47.70
        1.80 C 56.08 -0.90 65.46 4.21 69.03 11.97 C 71.67 17.65 71.59 24.74 70.62 30.81
        C 68.57 41.48 60.32 50.55 51.81 56.81 C 47.69 59.73 43.11 62.72 38.21 64.12 C
        34.80 65.13 31.23 63.34 28.24 61.86 C 19.69 57.27 11.77 50.76 6.25 42.72 C 0.82
        34.78 -0.33 24.87 1.66 15.60 C 3.69 7.15 12.14 0.18 20.99 1.04 Z" />
    <path
        android:fillColor="#1721dc"
        android:pathData="M 19.98 7.14 C 25.68 7.39 30.87 12.07 36.10 12.99 C 41.30 12.15 46.97 7.14 52.84
        7.35 C 58.72 7.85 63.41 12.52 64.67 18.17 C 65.71 23.40 65.21 29.32 63.25 34.30
        C 59.83 42.88 52.20 49.81 44.38 54.43 C 40.52 56.53 36.81 58.58 32.37 56.70 C
        24.56 53.51 17.02 47.75 12.20 40.77 C 7.31 33.87 5.58 24.79 7.64 16.59 C 9.15
        11.09 14.21 6.98 19.98 7.14 Z" />
</vector>

您有两种选择: 1)创建另一个矢量可绘制对象,它将只绘制外线,而不是重叠两颗心 要么 2)去掉橙色的心形,给蓝色的心形添加橙色的描边。只需复制下面的代码并尝试一下。请注意:笔划宽度的一半将在图像内部,一半将在图像外部,因此您的图像会有所不同(笔画将更靠近图像的中心)

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="72dp"
    android:height="66dp"
    android:viewportHeight="66"
    android:viewportWidth="72">
    <path
        android:fillColor="#00000000"
        android:strokeColor="#F7592B"
        android:strokeWidth="6"
        android:pathData="M 19.98 7.14 C 25.68 7.39 30.87 12.07 36.10 12.99 C 41.30 12.15 46.97 7.14 52.84
        7.35 C 58.72 7.85 63.41 12.52 64.67 18.17 C 65.71 23.40 65.21 29.32 63.25 34.30
        C 59.83 42.88 52.20 49.81 44.38 54.43 C 40.52 56.53 36.81 58.58 32.37 56.70 C
        24.56 53.51 17.02 47.75 12.20 40.77 C 7.31 33.87 5.58 24.79 7.64 16.59 C 9.15
        11.09 14.21 6.98 19.98 7.14 Z" />
</vector>

结果:click to see the resulting image

请像这样使用 StrokeColor 和 strokeWidth

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="72dp"
android:height="66dp"
android:viewportHeight="66"
android:viewportWidth="72">

<path
    android:fillColor="@android:color/transparent"
    android:pathData="M 0.00 0.00 L 72.00 0.00 L 72.00 66.00 L 0.00 66.00 L 0.00 0.00 Z" />
<path
    android:fillColor="#000000000"
    android:pathData="M 19.98 7.14 C 25.68 7.39 30.87 12.07 36.10 12.99 C 41.30 12.15 46.97 7.14 52.84
    7.35 C 58.72 7.85 63.41 12.52 64.67 18.17 C 65.71 23.40 65.21 29.32 63.25 34.30
    C 59.83 42.88 52.20 49.81 44.38 54.43 C 40.52 56.53 36.81 58.58 32.37 56.70 C
    24.56 53.51 17.02 47.75 12.20 40.77 C 7.31 33.87 5.58 24.79 7.64 16.59 C 9.15
    11.09 14.21 6.98 19.98 7.14 Z"
    android:strokeColor="#F7592B"
    android:strokeWidth="5"/>