[英]How to create custom shape using XML as a drawable in Android?
Have a look at this Gist.看看这个要点。
Above gist creates a drawable which looks like this:上面的要点创建了一个如下所示的可绘制对象:
Clearly in the gist, pathData
property has been provided coordinates.显然,在要点中,
pathData
属性已提供坐标。 How is this achieved, I mean, ofcourse someone doesn't found each point according to his needs.这是如何实现的,我的意思是,当然有人不会根据自己的需要找到每个点。
My question : How is this achieved?我的问题:这是如何实现的? Is there any tool present to do so?
是否有任何工具可以这样做?
Drawable like this reduces app size by avoiding to have an image instead.像这样的 Drawable 通过避免使用图像来减少应用程序的大小。 Also, there are questions for drawables in XML like this , this and many more but I think my Question is very different (and useful, probably).
此外,还有一些关于 XML 中的 drawable 的问题,例如this 、 this等等,但我认为我的问题非常不同(并且可能很有用)。
You can design your SVG files using some tools such as Android Vector Asset Studio你可以使用一些工具来设计你的 SVG 文件,比如Android Vector Asset Studio
Usually people don't write the SVG paths themselves, they use a tool or an editor where they sketch the drawing and generate the file.通常人们不会自己编写 SVG 路径,他们会使用工具或编辑器来绘制图形并生成文件。
What you have to do is to create a SVG image using an SVG editor such as Inkscape (the one I use) or if you want a more professional (and expensive) editor you can use Adobe Illustrator .您需要做的是使用 SVG 编辑器(例如Inkscape (我使用的))创建 SVG 图像,或者如果您想要更专业(和昂贵)的编辑器,您可以使用Adobe Illustrator 。 You can even use a tool called svg-edit which is accessible in the browser.
您甚至可以使用可在浏览器中访问的名为svg-edit的工具。
After creating your required art, save your SVG file.创建所需的艺术作品后,保存您的 SVG 文件。 Next goto and open Android Studio.
接下来转到并打开Android Studio。
Note: To ensure backward compatibility, add the following to your build.gradle注意:为确保向后兼容,请将以下内容添加到 build.gradle
android{
defaultConfig{
vectorDrawables.useSupportLibrary = true
}
}
dependencies{
compile 'com.android.support:appcompat-v7:23.2.0'
}
Hope this has helped you.希望这对你有帮助。 For more info see the official documentation .
有关更多信息,请参阅 官方文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.