2011-12-09 95 views
2

由於某種原因,我的Android項目編譯正常,在手機和模擬器上運行良好,甚至包括多個帶LinearLayouts,TextViews,按鈕,圖像甚至自定義視圖組件的XML佈局文件,但是當涉及到形狀時,它根本找不到它們。AndroidManifest:忽略未知的'形狀'XML元素

繼承人我的代碼:

<?xml version="1.0" encoding="utf-8"?> 
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 

    <solid android:color="#ffffff"/>  

    <stroke android:width="3dp" 
      android:color="#ff000000"/> 

    <padding android:left="1dp" 
      android:top="1dp" 
      android:right="1dp" 
      android:bottom="1dp"/> 

    <corners android:radius="30dp"/> 
</shape> 

我在eclipse獲得圖形佈局錯誤:

com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup 
Exception details are logged in Window > Show View > Error Log 
The following classes could not be found: 
- shape (Fix Build Path, Edit XML) 
- solid (Fix Build Path, Edit XML) 

我針對的Android 2.2 Froyo谷歌的API。

對此提出建議?

+1

就在我頭頂,你把這個XML文件放在res/drawable目錄下嗎? – dbryson

+0

不,分辨率。我認爲res/drawable是用於圖像?如何在xml佈局中繪製正方形? – Ring

回答

10

你可能會因爲把這個XML放在錯誤的地方而出錯。上面的XML應該在res/drawable目錄中。你真的不應該在佈局中畫一個方形。在視圖中繪製方形並將其添加到佈局。或者使用圖像並通過ImageView將其添加到View中。佈局是視圖的聚合。如果你真的想在佈局(ViewGroup)中繪製一個Square,你可以擴展一個並在onDraw()方法中繪製它。但那可能比需要更復雜。看看Layouts上的Android Docs:http://developer.android.com/guide/topics/ui/index.html

+0

感謝您的幫助,我最終將這個方形的繪圖代碼放入了res/drawable的xml文件中,然後我將它作爲ImageView添加到了我的佈局中。謝謝哥們。 但我現在還有一個問題,但如果您有興趣嘗試一下: http://stackoverflow.com/questions/8440983/draw-square-behind-text – Ring