2016-12-05 49 views
0

我試圖導入svg文件到Android Studio和我收到以下錯誤:「解析XML文件時出現異常:文件過早結束。」試圖導入SVG到Android工作室

Could not generate a preview

EXCEPTION in parsing prove.svg:

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

Premature end of file.

這是svg我有由時刻:

<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>

正如你所看到的,我沒有任何問題,如果我使用它在網絡上,因爲它渲染很好。

那麼,我錯過了什麼?我是否應該將其調整爲某種格式才能在Android Studio上使用它?

注:我已經搜查,似乎它必須適應於舊版本的Android Studio,因爲它沒有接受<circle>標籤,但我也有鋸,現在應該接受他們。現在我正在使用Android Studio 2.2

在此先感謝!

回答

1

好了,你可以試試這個SVG的方法here

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

或者,更好可擴展向量方法:

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

提示:由於矢量方法建議,有工具可以將SVG轉換爲矢量圖形以獲得複雜的曲線和路徑。

+0

好吧,似乎刪除像素單位它運作良好,並沒有拋出任何錯誤。謝謝 :) –

0

它不直接回答你的問題,但如果你想在Android中有一個基於矢量的圓圈,我強烈建議在下面的答案中看到可繪製的方法。

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

+0

我試圖簡化我的代碼到最基本的元素。我有一個不止一個圓圈的svg文件。使用上面的例子,它也給了我錯誤(我的意思是我提出的問題)。另外,我需要它在svg而不是形狀。 –

相關問題