英文:
Android Studio does not import all parts of an SVG Vector
问题
我想从Illustrator导入一些矢量图形来设计我的Android Studio应用程序。如果我将我的矢量图形导出为SVG,这将非常有效。我的项目的所有部分都成功导出,结果令人满意(图像1)。然而,当我在Android Studio中将这个SVG文件创建为新的矢量资源时,我的一个蓝色圆圈突然消失了(参见图像2)。为什么Android Studio不导入我的SVG的所有部分的原因可能是什么?或者原因可能是Illustrator的导出出现问题?
编辑:添加图片3以显示如果我使用在线转换器会发生什么。结果甚至更糟。
任何帮助都将不胜感激!
图1:
图2:
图3:使用在线转换器获取XML矢量时的结果(也是错误的)
英文:
I want to import some vector graphics from illustrator for the design of my android studio app. If I export my vector graphics as SVG, this works wonderfully. All parts of my project are successfully exported and the result is satisfactory (image 1). However, when I create this SVG file as a new Vector Asset in Android Studio, one of my blue circles is suddenly missing (see image 2). What can be the reasons why Android studio does not import all parts of my SVG? Or could the reason be a wrong export from illustrator?
Edit: Added Picture 3 to show what happens if I use a online converter instead. The output is even worse.
Any Help is appreciated!
Picture 1:
Picture 2:
Image 3...Result when I use a online converter to get a xml vector(also wrong)*
答案1
得分: 1
在转换器窗口中显示的SVG版本是由Android Studio内置的SVG渲染器渲染的。这只是SVG的预览。它不一定反映转换器的输出结果。
所以你看到的问题是与内置的SVG渲染器有关的。
矢量可绘制对象(VectorDrawables)实际上不支持渐变填充。至少转换器不支持它们。所以即使显示的SVG是完美的,生成的矢量可绘制对象也不会包含渐变圆。
所以你有一些替代方法:
- 将你的圆改为纯色填充,然后转换为矢量可绘制对象。
- 类似于#1,但通过使用预定义的渐变定义来添加渐变。
- 在你的应用程序中使用实际的SVG渲染库(例如AndroidSVG)。
- 切换到使用位图背景(即PNG)。
- 使用
Canvas
方法自己绘制背景。
个人而言,我会选择第3种方法。
英文:
The version of the SVG that is displayed in the converter window is rendered by a built-in SVG renderer in Android Studio. It's a preview of the SVG. It does not necessarily reflect what the output of the converter will be.
So the bug you are seeing is with the built-in SVG renderer.
VectorDrawables don't really support gradient fills. At least the converter doesn't support them. So even if the displayed SVG were perfect, the generated VectorDrawable won't include the gradient circles anyway.
So you have a few alternative approaches:
- Change your circles to solid fill and then convert to VectorDrawables.
- Like #1, but add gradients by using predefined gradient definitions.
- Use an actual SVG rendering library (like AndroidSVG) in your app.
- Switch to using a bitmap background (ie PNG)
- Draw the background yourself using
Canvas
methods.
Personally, I would go with #3.
答案2
得分: 0
Android Studio不能将复杂图形转换为矢量可绘制图形。它只能将平面图标转换为矢量图形。你必须在这里使用PNG图片!
英文:
Android Studio doesn't convert complex graphics into vector drawable. It only converts flat icons. You have to use a png here dude !!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论