Vector Drawable不显示垂直线

时间:2016-01-18 10:20:38

标签: android android-drawable android-vectordrawable

我正在使用向量在xml中创建drawable。我可以使用路径绘制一个矩形,但是当我试图绘制一条完全垂直或水平的线时,它没有显示。 这是我的代码

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">

    <path
        android:strokeWidth="1"
        android:strokeColor="#c1ae1e"
        android:pathData="M0 0,H24,V24,H0,V0"/>

    <path
        android:strokeWidth="3"
        android:strokeColor="#4c4c4c"
        android:fillColor="#36352c"
        android:pathData="M12 0,L12 24"/>

    <path
        android:strokeWidth="3"
        android:strokeColor="#4c4c4c"
        android:fillColor="#36352c"
        android:pathData="M0 12,L24 12"/>

</vector>

这是预览输出 - enter image description here

1 个答案:

答案 0 :(得分:1)

尝试将其合并为一个路径。我不确定为什么,但只有两个点的完全水平或垂直线不会渲染。由于我必须制作十字形状,所以我能够将垂直或水平线组合起来,如下所示:

    <path
    android:strokeColor="#FF000000"
    android:strokeWidth="0.5"
    android:pathData="M14,0 l0,28 M0,14 l28,0"/>

如果你制作一个计算得像直线的弧(也不是大多数人会做的事情,但我在更改弧值时看到它,并且可能与线条不显示的原因有关)也会发生这种情况)

尝试一下:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24.0"
    android:viewportHeight="24.0">

    <path
        android:strokeWidth="1"
        android:strokeColor="#c1ae1e"
        android:pathData="M0 0,H24,V24,H0,V0"/>

    <path
        android:strokeWidth="3"
        android:strokeColor="#4c4c4c"
        android:fillColor="#36352c"
        android:pathData="M12 0,L12 24 M0 12,L24 12"/>

</vector>