【问题标题】:Vector Drawable not showing vertical lineVector Drawable 不显示垂直线
【发布时间】:2016-01-18 10:20:38
【问题描述】:

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

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

这是预览输出-

【问题讨论】:

    标签: android android-drawable android-vectordrawable


    【解决方案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>
    

    【讨论】:

    • 我想要两条不同颜色的线兄弟!.:(
    • 似乎唯一可行的方法是把 0.001 (或者如果你想绝对确定,你可以走得更低,不管我放了多少个零,它一直接受它)位置 0。这绝对是一个错误,因为使用 h、H、v 和 V 也不起作用。我还没有发现任何说明它是 SVG 设计方式的一部分。
    • 更好的是,问题可能只出在预览版上。我做了一些测试,似乎水平和垂直线在设备上看起来很好 - 但这确实使预览对这些形状毫无用处。
    • 是的,这并没有只显示在预览中,我在设备上测试过,效果很好,谢谢!
    猜你喜欢
    • 2021-12-19
    • 1970-01-01
    • 2020-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-11
    • 2015-06-22
    相关资源
    最近更新 更多