2015년 12월 16일 수요일

SVG in Android


I believe vector graphics native supports for android had long been on the wish list and good news(?) is that from the release of API 21 (Android 5.0) VectorDrawable has been included. if used properly I don't think we have to prepare all the images for each different device resolutions, however still there exist some problems.
Android supports only basic level of vector graphics..

  • VectorDrawable supports paths using the ‘d’ attribute like the SVG format
  • VectorDrawable does not read/support the SVG format
  • VectorDrawable does not support gradients
  • VectorDrawable does not support numbers using scientific E notation (as commonly used in SVG)


Even though SVG format is not supported, we can still convert SVG files to VectorDrawables with Android Studio and open source tools like Inkscape, svg2android

Menu in Android Studio:
File > New > Vector Asset > Local Asset file > change options if required

Link:
Inkscape: https://inkscape.org/
svg2android: http://inloop.github.io/svg2android/


Maybe SVG not only helps to save some time for development, but also increase the visual quality, we need to be careful of using it, because it is rendered at runtime, so always need to keep the complexity of SVG files to minimum.

댓글 없음:

댓글 쓰기