9

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());
Andrew T.
  • 4,637
  • 8
  • 40
  • 60
Sadegh Hoseini
  • 119
  • 1
  • 4

2 Answers2

7

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.

BrentM
  • 5,521
  • 3
  • 30
  • 38
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.

CommonsWare
  • 954,112
  • 185
  • 2,315
  • 2,367