简体   繁体   English

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

[英]How to create a vector drawable with inner path transparent?

I am trying to create a favourite icon something like the following icon. 我正在尝试创建一个收藏夹图标,类似于以下图标。

在此处输入图片说明

While creating it i need the inner path (the area in blue color)to be transparent in the result.But while giving the transparent color it is showing the color that is filled in the outer path.ie complete shape in orange color. 创建它时,我需要内部路径(蓝色区域)在结果中是透明的。但是在给出透明颜色时,它显示的是填充在外部路径中的颜色。即完整的形状为橙色。 How i can i make a vector drawable with transparent inner path 我如何使带有透明内部路径的矢量可绘制

My vector drawable is 我的矢量可绘制为

<?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>

You have two ways to go: 1) create another vector drawable, which will draw only the outer line, instead of overlapping two hearts or 2) remove the orange heart and add an orange stroke to the blue heart. 您有两种方法:1)创建另一个可绘制的向量,该向量将仅绘制外线,而不是重叠两个心形;或2)删除橙色心形,并向蓝色心形添加橙色笔触。 Just copy the code below and try it. 只需复制下面的代码并尝试。 Be aware: half of the stroke width will go inside the image and half will go outside, so your image will differ a bit (stoke will be closer to the center of the image) 请注意:笔划宽度的一半将进入图像内部,一半将进入外部,因此您的图像会有所不同(笔划将更靠近图像中心)

<?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>

Result: click to see the resulting image 结果: 单击以查看生成的图像

Please use StrokeColor and strokeWidth like this 请像这样使用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"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM