0

I am trying to import a svg file to Android Studio and I am getting the following error:

Could not generate a preview

EXCEPTION in parsing prove.svg:

For input string: "60px"Exception while parsing XML file:

Premature end of file.

And this is the svg that I have by the moment:

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="150" height="150">
  <circle r="60px" fill="red" cx="90" cy="65"></circle>
</svg>

As you can see, I do not have any problems if I use it on the net because it is rendering well.

So, what am I missing? Should I adapt it to some format to use it on Android Studio?

Note: I have searched and it seems that it had to be adapted on old versions of Android Studio because it did not accept <circle> tags but I also have saw that now it should accept them. Now I am using Android Studio 2.2.

Thanks in advance!

Community
  • 1
  • 1
Francisco Romero
  • 12,787
  • 22
  • 92
  • 167

2 Answers2

1

Well, you can try this SVG approach here:

<svg height="100" width="100">
   <circle cx="50" cy="50" r="40" fill="red" />
</svg>

Or, the better and scalable vector approach:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="oval">
  <solid
    android:color="#ff0000"/>
</shape>

HInt: Since the vector method is recommended, there are tools online that can convert SVG to Vector graphics for complex curves and paths.

AlphaQ
  • 656
  • 8
  • 18
0

It doesn't directly answer your question but if you want to have a vector based circle in Android, I highly recommend the drawable approach seen in the below answer.

https://stackoverflow.com/a/34724737/2680506

Community
  • 1
  • 1
Dave S
  • 3,378
  • 1
  • 20
  • 34
  • I tried to simplify my code to the most basic element. I have a svg file with more than just one circle. Using the example above it also gives to me the error (I mean with the example that I put on my question). Also, I need it on svg and not as a shape. – Francisco Romero Dec 05 '16 at 20:54