0

I just want to see some SVG images, when i click on the app. I tried it. The steps to import into android studio was correct. But when i run the apk, i can see only a blank screen. The SVG image did'nt show up. So what can i do? How can i correct it? The code i used is,

import android.graphics.Color;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;

import com.larvalabs.svgandroid.SVG;
import com.larvalabs.svgandroid.SVGParser;


public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Create a new ImageView

        ImageView imageView = new ImageView(this);
        // Set the background color to white
        imageView.setBackgroundColor(Color.BLACK);
        // Parse the SVG file from the resource
        SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.android);
        // Get a drawable from the parsed SVG and set it as the drawable for the ImageView
        imageView.setImageDrawable(svg.createPictureDrawable());
        // Set the ImageView as the content view for the Activity
        setContentView(imageView);
    }
nan0133
  • 71
  • 1
  • 9
  • Which library are you using for SVG parsing? – AndroidEx Apr 15 '15 at 20:02
  • android-svg. i included this jar file in the "libs" folder. – nan0133 Apr 15 '15 at 20:09
  • ok, it's just that it has been unmaintained for some time, and quite recently I have successfully used its [fork](https://github.com/japgolly/svg-android), which is also unmaintained but not for so long. You may try using this library instead of the first one, they are quite similar in usage. And do you follow their requirements for input SVG files? They have a range of formats they support, the rest is not guaranteed. – AndroidEx Apr 15 '15 at 20:14
  • Thank u. I don't know about the requirements for input SVG files and the range of formats they support. Actually i just followed the steps given in the below link. http://android-coffee.com/svg-integration-in-android-studio/ – nan0133 Apr 15 '15 at 20:22
  • Here's their supported [formats](https://code.google.com/p/svg-android/wiki/Tutorial#How_to_Prepare_Your_Vector_Images). I recommend saving an image withing these parameters and trying again. – AndroidEx Apr 15 '15 at 20:30

1 Answers1

1

Your problem is likely caused by one of these two things:

  1. Hardware acceleration is turned on by default on recent Android devices and this causes issues as SVG rendering can require some features of Canvas that are not supported by the hardware accelearated renderer on some versions of Android. Each version of Android gets better, but you will probably have to explicitly tell it to use the software renderer.

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

  1. When you say "android-svg" I assume you mean "svg-android"? svg-android is not maintained and doesn't support a lot of SVG features. This may be the reason your SVG is not rendering. Try a newer fork, or another library like AndroidSVG.
Community
  • 1
  • 1
Paul LeBeau
  • 97,474
  • 9
  • 154
  • 181