什么是 Android 矢量绘图规范

What is the Android vector drawable specification

我正在尝试用 VectorDrawables 替换我所有的 Android 可绘制 png 资源。

在我使用 Android Studio 标准资产的地方显然一切都很好。

一些外部导入的 SVG 资源失败,因为 Android 不支持行业标准的 SVG 规范。

是否存在 Android 矢量绘图规范? 其中列出了 Android (Android Studio) 将接受的所有可接受的 SVG 命令?

据我所知,除了文档中的 VectorDrawable class 定义外,没有针对 VectorDrawable 格式的正式书面规范。

https://developer.android.com/reference/android/graphics/drawable/VectorDrawable

这个页面还有很多额外的信息:

https://developer.android.com/studio/write/vector-asset-studio

它们都没有导入器支持的 SVG 元素列表。但是,您可以在 Android 源代码中查看导入程序的代码,以获得有关支持内容的明确答案。源代码在这里:SVG2Vector.java

从代码中可以看出支持的SVG元素仅限于:

<polygon><rect><circle><line><path><g>

请注意,这些仅得到部分支持,因为仅处理了它们的一组有限属性。基本上只有 strokefill 相关的,加上 transformdisplay:none.

但是,还有其他第三方转换器声称可以做得更好。尽管他们可能支持的内容受限于 VectorDrawable 本身支持的内容。