Difference between SVG and VectorDrawable in Android

岁酱吖の 提交于 2019-12-23 12:03:31

问题


While Android supports SVG, why should it be converted to VectorDrawable?

This code example shows SVG in Android:

SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.android);
imageView.setImageDrawable(svg.createPictureDrawable());

回答1:


The SVGParser functionality you mention is a third party implementation of SVG support for Android.

The major problems with using SVG in Android are:

  • SVG files may be very complex and can be very slow to render

  • All the third party implementations I have used have had bugs and failed to load or render some SVG files correctly

  • Most of the third party implementations have been abandoned and none seem to be actively maintained

I have written more about using SVG files in Android and the available third party libraries in the following article:

https://androidbycode.wordpress.com/2015/02/27/vector-graphics-in-android-part-1-svg/

VectorDrawable supports of subset of SVG format that is designed to ensure it is fast to render. I have written about VectorDrawable and how to convert your existing SVG files to VectorDrawable here.




回答2:


While android supports SVG

No, it does not, other than via WebView or third-party SVG rendering libraries.

Why we should convert SVG to VectorDrawble?

You are welcome to show SVG files via WebView or third-party SVG rendering libraries. VectorDrawable is an option; it is not a requirement.

This code example shows svg in android:

There is no SVGParser class in the Android SDK.



来源:https://stackoverflow.com/questions/31926212/difference-between-svg-and-vectordrawable-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!