2012-12-01 28 views
1

我在我的繪製目錄中名爲off.xml的XML文件(是應該是一個紅色圓圈)...使用XML文件作爲繪製資源

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > 
<gradient android:startColor="#FFFF0000" android:endColor="#FFFF0000" 
    android:angle="270"/> 

在我的主頁我有以下XML ...

<LinearLayout android:layout_width="match_parent" 
    android:layout_height="50dip" android:orientation="horizontal">  
<View android:layout_width="40dip" 
    android:layout_height="0dip" android:layout_weight="1" 
    android:background="@drawable/off" /> 
</LinearLayout> 

我得到的錯誤「無法轉換@繪製/斷成繪製。紅圈不顯示。 (我已經把一個按鈕那裏,以確保其他婦女參與發展得到會顯示)

什麼是導致此錯誤。我從本論壇的另一篇文章中得到了應該工作的例子。 感謝,加里

回答

1

兩個問題:截止</shape>標籤中缺少您的繪製和的layout_height你視圖爲0或方向錯誤。

+0

我不錯過標籤。這個論壇有些錯誤,有時無法識別粘貼的線條。你的回答讓我想到了身高和體重,結果我必須將layout_weight放在linearlayout而不是視圖上。我仍然在Eclipse中看到錯誤,但紅圈顯示。 –

1

你@繪製/關閉佈局應該是

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item><shape android:shape="oval"> 
    <gradient android:startColor="#FFFF00" android:endColor="#FFFF00" 
     android:angle="270"/> 
    </shape></item> 
</selector> 
+0

這不會畫出橢圓形狀。 – dougcunha

+0

它不起作用。我犯了同樣的錯誤。 –

1

試試這個:

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="oval" > 

    <gradient 
     android:angle="270" 
     android:endColor="#FFFF0000" 
     android:startColor="#FFFF0000" /> 

</shape> 
+0

這與我所擁有的沒有什麼不同。 (無論如何我都試過了,仍然得到相同的錯誤)。 –