70

I'm wondering how vector drawing in Android with the Shape class may resemble another vector drawing standard.

Since Shape is a Drawable, and Drawables are usually defined as XML, it sounds a lot like the vector drawing commands in SVG.

My question is this: Has anybody created an XSLT transformation, or other mechanism, for converting an SVG drawing description into Android Shapes?

Buggieboy
  • 4,636
  • 4
  • 55
  • 79
  • I am also looking for something like this and am quite puzzled why this is not implemented jet. As you mentioned simple transformation of drawing commands would be enough (at least for a subset of SVG). I have even done this sometimes manually for very simple shapes (defining button backgrounds with gradient like this is great) and I am more or less clueless about SVG specifics. – Igor Čordaš Feb 27 '14 at 14:07
  • 4
    Great question, wrong call to close it. I think it is a fantastic idea to have a converter from SVG to Shape. I may write one, but I hate XSLT so I'd probably do it using C# or I guess it should be Java. – Martin Capodici Jun 10 '14 at 06:35
  • 2
    I would suggest you using VectorDrawable. The best solution I found is the BetterVectorDrawable lib together with the SVG to VectorDrawable Converter. **BetterVectorDrawable** is the VectorDrawable implementation for Android 4.0+ with configurable fall-back behavior on Android 5.0+. **SVG to VectorDrawable Converter** is the batch converter of SVG images to Android VectorDrawable XML resource files. Online version: http://a-student.github.io/SvgToVectorDrawableConverter.Web/ – A-student Sep 10 '15 at 11:42

6 Answers6

26

Another non-GPL'd library (this one is Apache License 2.0), the one used in Google's Androidify app: svg-android

https://github.com/pents90/svg-android

rekire
  • 47,260
  • 30
  • 167
  • 264
dgmltn
  • 3,833
  • 3
  • 25
  • 27
11

Well, not exactly. But I do have ported libsvg to android, which enables you to load SVG files and plot them to a Canvas.

Please check out:

https://launchpad.net/libsvg-android

Anton P
  • 121
  • 2
6

The closest thing that I could find was svg4mobile.

While I don't believe that it does transformations to Drawables XML, it does read the svg and make the appropriate calls to the Drawable classes.

Buggieboy
  • 4,636
  • 4
  • 55
  • 79
2

Besides the 2 GPL libraries mentioned, there is a commercial library called TinyLine that implements the SVG Tiny subset, which although more limited may be a better licensing choice, if you want to create a non-GPL'd application.

Mark
  • 2,362
  • 18
  • 34
2

Currently some people including me work on it independently.
You may find working solution in these articles:
  Android. ImageView with SVG Support.
  Android ImageView and Drawable with SVG support

Pavel Chernov
  • 1,807
  • 1
  • 16
  • 15
  • tried both can't compile it the ndk part, it would be halpfully if you would update the project settings –  Oct 06 '13 at 15:01
2

The great AndEngine has an extension for loading SVG and rasterizing it into the texture with any resolution, with color replacement and other great features. Really works. For example you can try a free game by engine author.

Note: The engine best suited for full-screen 2D games and is based on OpenGL 2 view. LGPL

Alexey Gopachenko
  • 7,458
  • 3
  • 27
  • 25