android - SVG 路径转换为 ​​Android Drawable 失败

标签 android svg android-vectordrawable

svg

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   width="382"
   height="350"
   id="svg2"
   version="1.1">
  <path
     style="fill:#000000;fill-opacity:1;fill-rule:nonzero"
     d="M 190.46289,1.9140625 A 77.437241,77.375557 89.625608 0 0 113.5957,79.855469 77.437241,77.375557 89.625608 0 0 113.7832,84.326172 77.437241,77.375557 89.625608 0 0 80.462891,76.914062 77.437241,77.375557 89.625608 0 0 3.5957031,154.85547 77.437241,77.375557 89.625608 0 0 60.125,228.85742 a 77.437241,77.375557 89.625608 0 0 -11.529297,40.99805 77.437241,77.375557 89.625608 0 0 77.880857,76.92969 77.437241,77.375557 89.625608 0 0 64.4668,-35.50196 77.437241,77.375557 89.625608 0 0 65.5332,35.50196 77.437241,77.375557 89.625608 0 0 76.86719,-77.94141 77.437241,77.375557 89.625608 0 0 -10.49805,-38.25 77.437241,77.375557 89.625608 0 0 55.49805,-74.75 77.437241,77.375557 89.625608 0 0 -77.88086,-76.929688 77.437241,77.375557 89.625608 0 0 -32.44727,7.470704 77.437241,77.375557 89.625608 0 0 0.32813,-7.541016 A 77.437241,77.375557 89.625608 0 0 190.46289,1.9140625 Z M 105.5,98.5 l 170,0 c 8.31,0 15,6.69 15,15 l 0,126 c 0,8.31 -6.69,15 -15,15 l -101.05859,0 -72.81446,35.29688 L 130.59961,254.5 105.5,254.5 c -0.84458,0 -1.66687,-0.0859 -2.47266,-0.21875 l -1.72265,0.002 0,-0.38476 C 95.051207,252.09077 90.5,246.35121 90.5,239.5 l 0,-126 c 0,-8.31 6.69,-15 15,-15 z"
     id="svg_6" />
</svg>

在所有经过测试的浏览器和 Inkscape 中看起来都是这样的: enter image description here

如果我使用 awesome svg2android tool 对其进行转换,我得到了xml文件

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

    <path
        android:fillColor="#000000"
        android:pathData="M 190.46289,1.9140625 A 77.437241,77.375557 89.625608 0 0 113.5957,79.855469
77.437241,77.375557 89.625608 0 0 113.7832,84.326172 77.437241,77.375557
89.625608 0 0 80.462891,76.914062 77.437241,77.375557 89.625608 0 0
3.5957031,154.85547 77.437241,77.375557 89.625608 0 0 60.125,228.85742 a
77.437241,77.375557 89.625608 0 0 -11.529297,40.99805 77.437241,77.375557
89.625608 0 0 77.880857,76.92969 77.437241,77.375557 89.625608 0 0
64.4668,-35.50196 77.437241,77.375557 89.625608 0 0 65.5332,35.50196
77.437241,77.375557 89.625608 0 0 76.86719,-77.94141 77.437241,77.375557
89.625608 0 0 -10.49805,-38.25 77.437241,77.375557 89.625608 0 0 55.49805,-74.75
77.437241,77.375557 89.625608 0 0 -77.88086,-76.929688 77.437241,77.375557
89.625608 0 0 -32.44727,7.470704 77.437241,77.375557 89.625608 0 0
0.32813,-7.541016 A 77.437241,77.375557 89.625608 0 0 190.46289,1.9140625 Z M
105.5,98.5 l 170,0 c 8.31,0 15,6.69 15,15 l 0,126 c 0,8.31 -6.69,15 -15,15 l
-101.05859,0 -72.81446,35.29688 L 130.59961,254.5 105.5,254.5 c -0.84458,0
-1.66687,-0.0859 -2.47266,-0.21875 l -1.72265,0.002 0,-0.38476 C
95.051207,252.09077 90.5,246.35121 90.5,239.5 l 0,-126 c 0,-8.31 6.69,-15 15,-15
z" />
</vector>

在 Android Studio 预览中看起来像这样: enter image description here

我无法发现路径数据中的错误。你可以吗? (我还将 svg 路径数据直接复制到 xml,这会产生相同的渲染)

最佳答案

你的初始 svg 有问题,我用 illustrator 更新了它,无论如何这里是 Android 的 xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="374dp"
        android:height="344dp"
        android:viewportWidth="374.751"
        android:viewportHeight="344.874">
    <path
        android:fillColor="#FF000000"
        android:pathData="M186.9,0c-42.7,0.3 -77.1,35.2 -76.9,77.9c0,1.5 0.1,3 0.2,4.5c-10.4,-4.9 -21.8,-7.5 -33.3,-7.4c-42.7,0.3 -77.1,35.2 -76.9,77.9c0.3,34.5 23.3,64.7 56.5,74c-7.6,12.3 -11.6,26.5 -11.5,41c0.3,42.8 35.1,77.2 77.9,76.9c0,0 0,0 0,0c26.1,-0.2 50.3,-13.5 64.5,-35.5c14.3,22.3 39.1,35.7 65.5,35.5c42.7,-0.3 77.1,-35.2 76.9,-77.9c-0.1,-13.4 -3.7,-26.6 -10.5,-38.3c33.1,-9.8 55.7,-40.2 55.5,-74.8c-0.3,-42.8 -35.1,-77.2 -77.9,-76.9c0,0 0,0 -0,0c-11.2,0.1 -22.3,2.7 -32.4,7.5c0.2,-2.5 0.3,-5 0.3,-7.5C264.5,34.2 229.6,-0.3 186.9,0C186.9,0 186.9,0 186.9,0zM101.9,96.6h170c8.3,0 15,6.7 15,15v126c0,8.3 -6.7,15 -15,15H170.8l-72.8,35.3l29,-35.3h-25.1c-0.8,0 -1.7,-0.1 -2.5,-0.2l-1.7,0v-0.4c-6.3,-1.8 -10.8,-7.5 -10.8,-14.4v-126C86.9,103.3 93.6,96.6 101.9,96.6z"/>
</vector>

(另一方面,您现在可以使用 android studio 右键单击​​>新建>矢量资源创建矢量断言,并且您可以直接导入 svg )

关于android - SVG 路径转换为 ​​Android Drawable 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38250145/

相关文章:

android - 从 Android 设备获取超过 10000 个联系人

android - Firebase AdMob 抛出 IncompatibleClassChangeError

javascript - 如何制作动画绘图效果? (最好仅限 css3)

java - android.os.BinderProxy 无法转换为 org.eclipse.paho.android.service.MqttServiceBinder

android - Listview android中的Edittext

css - 如何使用 CSS3 为 SVG 的特定部分制作动画?

javascript - angularjs ng重复svg跳过空值索引

android - 如何使用 minSdkVersion 21 从矢量可绘制启动器图标生成 png?

android - AnimatedVectorDrawable/ObjectAnimator startoffset 错误?

android - 在可绘制资源 xml 中为 VectorDrawable 着色