2011-06-28 93 views
7

我試圖創建與在外面和圓形的內方角佈局的邊界。我收集了,我需要創建兩個形狀組成的XML定義繪製:一個筆劃寬度和拐角半徑和另一隻筆劃寬度:方形佈局邊界內邊

可繪製/

round_border.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <stroke android:width="4dp" android:color="#FF000000" /> 
    <padding android:left="7dp" android:top="7dp" 
      android:right="7dp" android:bottom="7dp" /> 
    <corners android:radius="4dp" /> 
    <solid android:color="#FFC0C0C0" /> 
</shape> 

square_border.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <stroke android:width="2dp" android:color="#FF000000" /> 
    <solid android:color="#FFC0C0C0" /> 
</shape> 

每個作品的independantly作爲邊界時appliedby本身就像這樣:

機器人:背景= 「@繪製/ round_border」,但是當它們之一或兩者都加入到一個項目,列表中可繪製的,像這樣:

composite_border.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <layer-list> 
     <item android:drawable="@drawable/round_border"/> 
     <!-- <item android:drawable="@drawable/square_border"/> --> 
    </layer-list> 
</shape> 

和:

機器人:背景=「@繪製/ composite_border」

佈局的背景完全是黑色的,而不是隻是一個黑色邊框 - 任何人都知道如何使該任務的圖層列表的工作?

+0

感謝分享這! – cV2

回答

2

square_border.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <stroke android:width="2dp" 
      android:color="#FF000000" 
    /> 
    <solid android:color="#FFC0C0C0" /> 
</shape> 

composite_border.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <layer-list> 
     <item android:drawable="@drawable/round_border"/> 
     <!-- <item android:drawable="@drawable/square_border"/> --> 
    </layer-list> 
</shape> 

注意的意見和引號! =]

+0

謝謝 - 我修復了帖子。 – jchristof

+0

謝謝 - 雖然仍在尋找答案。 – jchristof

4

Shape Drawable Doc你可以看到形狀不能有層列表裏面,所以你應該這樣定義

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item android:drawable="@drawable/square_border"/> 
    <item android:drawable="@drawable/round_border"/> 
</layer-list> 

注意,我改變了你的項目的順序,層內部的你composite_border.xml -list爲層列表
Each drawable in the list is drawn in the order of the list—the last drawable in the list is drawn on top
的文檔中所述,你希望它從外部

0

的平方試試這將工作不夠細:

solid背景顏色

stroke邊境

<?xml version="1.0" encoding="utf-8"?> 
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <solid 
     android:color="@color/white"/> 
    <stroke android:width="1dp" android:color="#ffaaaaaa" /> 
    <size 
     android:width="15dp" 
     android:height="15dp"/> 
</shape> 
2

創建一個XML文件

像round_background。XML

<?xml version="1.0" encoding="utf-8"?> 
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="oval"> 
    <solid 
     android:color="#CCCC33"/> 
    <size 
     android:width="35dp" 
     android:height="35dp"/> 
</shape> 

在佈局設置爲背景

<LinearLayout 
       android:id="@+id/layout_wellbeing" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:gravity="center" 
       android:background="@drawable/rounded_corner_leuvan" 
       android:orientation="horizontal" > 
</LinearLayout>