I get just blank white screen while using svg-android

3.8k views Asked by At

Purpose: I want to display an SVG image file using preferably an ImageView.

Attempt 1:

  • I'm using the svg-android library to do that.

  • I'm following their tutorial word for word. I just copy pasted their code into my onCreate, commented out my app code from onCreate.

    I have a splash screen coming before this, but I doubt that'll interfere with this in anyway. In any case, I'll just change the launch intent and post an update.

  • I've added their jar into the libs folder and referenced it.

Result 1:

I'm testing on samsung galaxy I93000 (International version)

All I get is a white screen.

No compilation or runtime errors.

Logcat output is as follows:

01-13 01:22:11.755: D/dalvikvm(24889): GC_FOR_ALLOC freed 52K, 7% free 12198K/12995K, paused 17ms, total 17ms
01-13 01:22:11.765: I/dalvikvm-heap(24889): Grow heap (frag case) to 17.000MB for 4642816-byte allocation
01-13 01:22:11.810: D/dalvikvm(24889): GC_CONCURRENT freed 1K, 5% free 16730K/17543K, paused 15ms+2ms, total 43ms
01-13 01:22:12.080: D/dalvikvm(24889): GC_FOR_ALLOC freed <1K, 5% free 16731K/17543K, paused 13ms, total 13ms
01-13 01:22:12.100: I/dalvikvm-heap(24889): Grow heap (frag case) to 21.928MB for 5168972-byte allocation
01-13 01:22:12.125: D/dalvikvm(24889): GC_CONCURRENT freed <1K, 4% free 21779K/22599K, paused 12ms+2ms, total 25ms
01-13 01:22:12.560: D/libEGL(24889): loaded /system/lib/egl/libEGL_mali.so
01-13 01:22:12.595: D/libEGL(24889): loaded /system/lib/egl/libGLESv1_CM_mali.so
01-13 01:22:12.600: D/libEGL(24889): loaded /system/lib/egl/libGLESv2_mali.so
01-13 01:22:12.605: D/(24889): Device driver API match
01-13 01:22:12.605: D/(24889): Device driver API version: 10
01-13 01:22:12.605: D/(24889): User space API version: 10 
01-13 01:22:12.605: D/(24889): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct 16 15:37:13 KST 2012 
01-13 01:22:12.670: D/OpenGLRenderer(24889): Enabling debug mode 0

Update 1:

I've tried making the activity that shows SVG graphic as the main activity from the manifest. There is no change in results.

Update 2:

Trying another library/way to do this - ImageView with SVG Support. Will post back with results.

Update 3:

Just so you know, I've already taken a look at SVG support on Android. The answers there do not really provide a native solution. One workaround would be to create static html pages, one for each svg, referencing the SVG js library. This doesn't seem maintainable at all. I would be that person people curse when they look at legacy code.

As you might have guessed the above trial didn't work out quite well.

2

There are 2 answers

5
znggo On BEST ANSWER

You've probably already found a solution, but for future reference:

I'm testing on samsung galaxy I93000 (International version)

All I get is a white screen.

No compilation or runtime errors.

You probably need to disable hardware acceleration for the ImageView that you're using:

imageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

I had this exact same problem with a fork of svg-android and it was solely due to hardware acceleration.

2
Dheeraj Bhaskar On

Ok, after one complete sleepless night, this is what I have. :)

Hope 1:

*TPSVG_Android_SVG_Library:* (This is what I used i.e. My Stamp of Approval ;) )

Tried this blessed person's library. Worked like a charm. He extends his custom view from View so you have most of the basic parameters for layouting. It has just one contributor. I'm slightly averse to using it on production stuff, atleast on a long term basis. But kudos to his work and many thanks as it satisfied my immediate need.

The usage is pretty straight forward for this one, anywho I shall describe it roughly.

  • Download the repo as a zip and import it into eclipse
  • Add it as a library project into your project (Project Properties -> Android)
  • Use it like so in onCreate:

    SVGView svgView = (SVGView)this.findViewById(R.id.svgImage); SVGParserRenderer image = new SVGParserRenderer(this, R.raw.anime); svgView.setSVGRenderer(image, null); svgView.setBackgroundColor(Color.WHITE);

  • I've used a FrameLayout to position this. lotta trial and error was needed as this doesn't show up in the WYSIWYG editor for android. You may temporarily replace this with ImageView and deal with the formatting.

  • Any parameters used in this tag that do not belong in the View class will cause compilation errors

ISSUE: I haven't quite figured out yet how to switch drawables(SVG) on this View during runtime. If anyone figures that out, kindly post the procedure.

Hope 2:

Vectoroid:

This one seems promising. They have a few vector based apps out along with the library. I couldn't quite figure how to use this to load a SVG drawable (seems like that's not supported yet). But wait! here on their blog they say that they've implemented the "SVG to drawable" and will be releasing it out soon. Yay!