当我使用渐变作为填充颜色时,为什么不出现边框?

时间:2018-01-16 17:06:18

标签: android linear-gradients android-vectordrawable

对于我的项目,我想使用矢量图像作为图标,但我遇到了一个问题。当我使用android:fillColor的渐变时,android:strokeColorandroid:strokeWidth定义的边框下方的代码不会出现在应用中。将android:fillColor直接添加到path时,它会起作用,但之后我会失去渐变。

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:aapt="http://schemas.android.com/aapt"
    android:width="32dp"
    android:height="56dp"
    android:viewportHeight="56.0"
    android:viewportWidth="32.0">
    <path
        android:fillType="evenOdd"
        android:pathData="M4,1L28,1A3,3 0,0 1,31 4L31,52A3,3 0,0 1,28 55L4,55A3,3 0,0 1,1 52L1,4A3,3 0,0 1,4 1z"
        android:strokeColor="#000000"
        android:strokeWidth="1.4">
        <aapt:attr name="android:fillColor">
            <gradient
                android:endX="17.0"
                android:endY="56.0"
                android:startX="17.0"
                android:startY="2.0"
                android:type="linear">
                <item
                    android:color="#FFFFFFFF"
                    android:offset="0.0" />
                <item
                    android:color="#FFD1D2D1"
                    android:offset="1.0" />
            </gradient>
        </aapt:attr>
    </path>
    ...
</vector>

这就是我现在使用的Nexus 5X和Pixel 2 XL仿真器:

icon without borders

这就是我想要实现的目标。这是我从Android Studio中截取的屏幕截图的一部分,它可以正确呈现矢量:

icon with borders

0 个答案:

没有答案