2010-12-10 101 views
2

你好我試圖繪製有三個長方形的形狀: 1.純色2.等級3.白線,我該怎麼辦呢?當我嘗試這個時,它不起作用。佈局具有父級顏色。嵌套形狀

<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" 
    android:height="60px" 
    > 
    <shape 
     android:shape="rectangle" 
     android:height="30px" 
     > 
     <solid 
      android:color="#ff297baf" 
      /> 
    </shape> 
    <shape 
     android:shape="rectangle" 
     android:height="30px" 
     > 
     <gradient 
    android:type="linear" 
    android:startColor="#ff297baf" 
    android:endColor="#ff16c0e3" 
    android:angle="270"/> 
    </shape> 
    <shape 
     android:shape="rectangle" 
     android:height="3px" 
     > 
     <solid 
      android:color="#FFFFFFFF" 
      /> 
    </shape> 
</shape> 

我想使3種顏色的漸變。以純色開始#ff297baf,在60%處開始從#ff297baf#ff16c0e3的漸變,並在最後添加一行。

+0

這裏需要給予更多的信息。你有迄今爲止嘗試的代碼示例嗎?爲什麼你需要一個純色和漸變?它是一個透明的漸變疊加?白線,這是一個輪廓?它應該放在形狀內嗎? – kcoppock 2010-12-10 22:07:15

+0

請將您的評論添加到問題中並進行格式化。 – 2010-12-10 23:42:24

+0

其不透明覆蓋。白線是一個輪廓。通常我會在HTML中執行此操作:「border-bottom:solid 2px white」。它不必在裏面做,但我不能在視圖上獲得任何其他形狀。編譯器抱怨應該是root。 – dropsOfJupiter 2010-12-11 00:03:37

回答

8

如果你要考慮使用多種形狀,你應該嘗試LayerListDrawable。像這樣的東西適用於我,但僅限於60px的示例高度。您可能需要修改,以適合您的具體需要,但是這應該給你一個良好的開端:

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item> 
    <shape android:shape="rectangle"> 
     <gradient 
      android:angle="270" 
      android:endColor="#ff16c0e3" 
      android:startColor="#ff297baf" 
      android:type="linear" /> 
    </shape> 
</item> 
<item android:top="57px"> 
    <shape android:shape="rectangle"> 
     <solid android:color="#FFFFFFFF" /> 
     <size android:height="3px" /> 
    </shape> 
</item> 

+0

這絕對奏效!非常感謝你! – dropsOfJupiter 2010-12-13 17:19:26