2016-09-21 63 views
1

我在Illustrator中创建了一个简单的播放按钮图像,将其保存为SVG,使用在线SVG到Drawable转换器创建该文件的xml,然后尝试使用Android Studio的Vector Asset工具将文件导入到我的项目中。但是,导入时,绘图元素中的一个元素丢失了,在这种情况下,圆形中间的白色三角形不存在。将Vector资源导入Android Studio时出错

play_circle.xml(转换后的XML文件)

<?xml version="1.0" encoding="utf-8"?> 
<vector xmlns:android="http://schemas.android.com/apk/res/android" 
    android:viewportWidth="94" 
    android:viewportHeight="102" 
    android:width="94dp" 
    android:height="102dp"> 
    <path 
     android:pathData="M85 52.5A38.5 38.5 0 0 1 46.5 91 38.5 38.5 0 0 1 8   
52.5 38.5 38.5 0 0 1 46.5 14 38.5 38.5 0 0 1 85 52.5Z" 
    android:strokeWidth="2" 
    android:fillColor="#424900" 
    android:strokeAlpha="0.29" 
    android:fillAlpha="0.29" 
    android:strokeColor="#000000" 
    android:strokeMiterLimit="10" /> 
<path 
    android:pathData="M71.39 51.63L34.81 30.51" 
    android:fillColor="#ffffff" /> 
</vector> 

play_button.svg, as created in illustrator and how it's intended to be

how it appears after being imported into android studio.Using Android Studio's Vector Asset Studio tool, you can see that the white triangle is already missing.

+0

您是否在drawable-v21中添加了此xml? –

+0

是的。为了澄清,无论何时我在Android Studio中打开Vector Asset Import工具,图像已经混乱(不显示中间的白色三角形)。我不知道这个工具是否有bug – RustWebDev

+0

你可以添加原始的SVG文件吗? – kazhiu

回答

4

虽然转换PNG至SVG有一些我们需要遵循的规则。所有转换器都不能正常工作。在我的情况下,我找到了最好的转换器网站,它会给你预览图像,以确认在转换过程中,这将要求免费注册,然后你可以下载你的svg文件。

Convert PNG to SVG

产生SVG后,使用以下工具将SVG转换为矢量绘制(这是必要的,因为不知何故机器人工作室是不是能够导入通过随机转换器产生的所有格式和样式)

Generate vector drawable from SVG

我为您的图像做了上述步骤。我创建了完美的矢量绘制,您可以通过创建新的xml直接复制到您的可绘制文件夹。 (通过作为源代码进行测试,请享受!)

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

<path 
    android:fillColor="#ffffff" 
    android:pathData="M 0.00 0.00 L 136.94 0.00 C 136.87 48.67 136.95 97.33 136.88 146.00 C 137.12 
147.64 136.29 149.93 138.00 151.00 L 0.00 151.00 L 0.00 0.00 Z" /> 
    <path 
    android:fillColor="#c7c9b7" 
    android:pathData="M 136.94 0.00 L 138.00 0.00 L 138.00 151.00 L 138.00 151.00 C 136.29 149.93 
    137.12 147.64 136.88 146.00 C 136.95 97.33 136.87 48.67 136.94 0.00 Z" /> 
<path 
    android:fillColor="#c7c9b7" 
    android:pathData="M 60.36 18.50 C 77.71 16.46 95.72 22.52 108.36 34.56 C 120.55 46.19 127.59 63.12 
    126.81 79.99 C 126.14 101.98 112.25 123.13 91.95 131.82 C 81.01 137.33 68.13 
    138.47 56.13 136.23 C 37.74 133.08 21.41 120.27 13.46 103.43 C 7.33 90.93 6.03 
    76.16 9.58 62.73 C 14.43 43.60 29.48 27.32 48.31 21.29 C 52.28 20.16 56.25 18.96 
    60.36 18.50 Z" /> 
<path 
    android:fillColor="#ffffff" 
    android:pathData="M 46.98 47.96 C 46.74 46.39 47.53 43.71 49.61 44.42 C 67.56 54.69 85.44 65.06 
    103.33 75.43 C 104.44 75.89 105.51 76.60 105.76 77.86 C 105.26 78.65 104.62 
    79.29 103.84 79.80 C 86.11 90.08 68.32 100.27 50.60 110.59 C 49.59 111.11 48.54 
    111.11 47.46 110.58 C 47.35 110.18 47.12 109.38 47.01 108.98 C 46.95 88.64 47.03 
    68.30 46.98 47.96 Z" /> 
</vector> 
0

我没有任何我的资产可以被矢量资产工作室理解。原因是我的系统是法文的。由于,与svg路径中的.不同,因此它在英语中需要它,并且会自动在系统的语言环境中进行翻译。 尝试使您的系统运行英文语言环境(在操作系统级别 - 更改语言)