Difference between SVG and VectorDrawable in Andro

2019-06-24 05:37发布

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());

2条回答
淡お忘
2楼-- · 2019-06-24 06:08

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.

查看更多
萌系小妹纸
3楼-- · 2019-06-24 06:09

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.

查看更多
登录 后发表回答