shape的使用

轉載:http://blog.csdn.net/lovexieyuan520/article/details/39188441html


在使用shape做爲背景的時候,代碼以下:android

[html] view plain copyide

  1. <?xml version="1.0" encoding="utf-8"?>  url

  2. <shape xmlns:android="http://schemas.android.com/apk/res/android" >  spa

  3.     <corners android:topLeftRadius="30dp" android:bottomLeftRadius="30dp"  .net

  4.         android:topRightRadius="0dp" android:bottomRightRadius="0dp"/>  orm

  5.     <solid android:color="#ff0000"/>  xml

  6. </shape>  htm

在android3.0以上顯示正常以下:blog



可是在android3.0如下,好比android2.3.3結果以下:


這顯然不符合咱們的要去,我想了不少辦法都沒能解決,只有經過圖片背景來實現,但我在stackoverflow看到一方案計較好,記錄一下:

代碼以下:

[html] view plain copy

  1. <?xml version="1.0" encoding="utf-8"?>  

  2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >  

  3.     <item>  

  4.       <shape   

  5.         android:shape="rectangle">  

  6.             <solid android:color="#FF0000" />  

  7.             <corners android:radius="30dp"/>  

  8.         </shape>  

  9.    </item>  

  10.   

  11.    <item android:left="30dp"  

  12.         >  

  13.       <shape   

  14.         android:shape="rectangle">  

  15.             <solid android:color="#FF0000" />  

  16.         </shape>  

  17.    </item>  

  18.   

  19. </layer-list>  

如今效果都同樣了,android2.3.3效果以下:


相關文章
相關標籤/搜索