简体   繁体   中英

“Exception while parsing XML file: Premature end of file.” trying to import svg to Android Studio

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!

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM