1

I am using the standard code stated in the example of the library of https://code.google.com/p/svg-android/wiki/Tutorial, here is my OnCreate method :

   @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);

        ImageView imageView =  (ImageView)findViewById(R.id.imageViewTest);
        // Set the background color to white
        imageView.setBackgroundColor(Color.GRAY);
        // Parse the SVG file from the resource
        SVG svg = SVGParser.getSVGFromResource(getResources(), R.drawable.android);

        //Get a drawable from the parsed SVG and set it as the drawable for the ImageView
        imageView.setImageDrawable(svg.createPictureDrawable());
    }

I am not able to add the layout code here, so sharing it in this doc: https://docs.google.com/document/d/1fbi3B_hAYUh_C2IwPfInvZ-BG2bgsa4pZoJKj8NBT9o/edit?usp=sharing

It does not give any error but it also does not display the image.

I was earlier getting doubts that the image is incorrect, then I used the one in the same example.

Yet it is not displaying the image nor giving any error.

Please suggest how to debug further.

Selfx Aadhyant
  • 363
  • 3
  • 8
  • why do you need an svg image? – Suhail Mehta Oct 15 '14 at 18:16
  • possible duplicate of [Having issue on Real Device using vector image in android. SVG-android](http://stackoverflow.com/questions/18356098/having-issue-on-real-device-using-vector-image-in-android-svg-android) – Paul LeBeau Oct 16 '14 at 01:19

3 Answers3

1

On newer devices have hardware rendering turned on by default so you need to explicitly turn on software rendering. use this after your code: imageView.setLayerType(View.LAYER_TYPE_SOFTWARE,null);

0

The best practice for SVG on Android is going to be to use a tool to convert your SVG to PNG at the size(s) you're interested in. Existing SVG support for Android is not comprehensive of what you're likely to find in an SVG file, and even if it were, the support is not built into the OS so using them directly is out of source .

If the library you're working with can process the SVGs you have well, you can make it work for every icon but not through the standard Android API; you'll need to create a custom view. Around months ago I used the library you linked and at that time it had trouble with many SVGs I had created in Inkscape or downloaded from various places. Perhaps its support has improved since then, but I recommend testing it with the exact SVGs you plan to use before you write a lot of custom code for it.

Suhail Mehta
  • 5,514
  • 2
  • 23
  • 37
  • thanks a lot for this information... I will consider this as the best answer and avoid the use of SVGs, however I was wondering why the very standard example and the image provided by the developers themselves is not working. – Selfx Aadhyant Oct 15 '14 at 18:40
  • that can with the lib you are using for de-compling the SVG image. – Suhail Mehta Oct 16 '14 at 05:42
0

Your problem is almost certainly hardware acceleration. You may need to set the View LayerType to software mode.

See Having issue on Real Device using vector image in android. SVG-android

If that doesn't fix it, then it may be an issue with svg-android, which can have trouble rendering correctly anything other than simple SVGs. You might have better luck with my library AndroidSVG.

Community
  • 1
  • 1
Paul LeBeau
  • 97,474
  • 9
  • 154
  • 181
  • Thank you @BigBadaboom, Works like a charm, sticking to svg-android for now, if I run it further bottlenecks will try your library – Selfx Aadhyant Oct 16 '14 at 09:23