2013-03-20 8 views
30

丸い角と塗りつぶされた色の背景を持つレイアウトを作成したいと思います。レイアウトにカラー背景とボーダー半径を追加する

これは私のレイアウトです:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="210dp" 
    android:orientation="vertical" 
    android:layout_marginBottom="10dp"   
    android:background="@drawable/offerItemLayout"> 
    <LinearLayout 
     android:id="@+id/offerImageHolder" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 
      . 
      . 
      . 
    </LinearLayout> 
</LinearLayout> 

私が正しく国境を作成し、次の描画可能なXML(offerItemLayout)があります。

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape xmlns:android="http://schemas.android.com/apk/res/android" 
       android:shape="rectangle"> 
      <corners 
       android:radius="5dp"/> 
      <stroke 
       android:width="1dp" 
       android:color="@color/bggrey" />    
     </shape> 
    </item> 
    // The lines below causes an inflation failure. 
    <item> 
     <fill 
      android:color="@color/white"/> 
    </item> 
</layer-list> 

をしかし塗りつぶして項目を挿入すると、インフレを引き起こしレイアウトの失敗が失敗します。

さらに、内部のLinearLayout(offerImageHolder)にカラーの背景を割り当てると、丸い角で最初の背景が上書きされます。

これを正しく行うことについてのご意見はありますか? :/

答えて

69

個別の記入項目は必要ありません。実際、無効です。ブロックsolidをブロックshapeに追加するだけです。その後のstrokesolidの上に描画します:

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

    <corners android:radius="5dp" /> 
    <solid android:color="@android:color/white" /> 
    <stroke 
     android:width="1dip" 
     android:color="@color/bggrey" /> 
</shape> 

一つだけshapeを持っている場合にもlayer-listは必要ありません。

+1

私が望むボーダーが底部にのみある場合はどうなりますか? – Si8

+0

@ SiKni8 doableしかし、それは別の質問です、私は実際にここに投稿することはできません。あなたが新しい質問をしてそれに私に警告するなら、私は答えを投稿します。 –

+0

カードの色の境界線を追加したいと思います... – Si8

11

drawableフォルダ内のbackground.xml。

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
<solid android:color="#FFFFFF"/>  
<stroke android:width="3dp" 
     android:color="#0FECFF" /> 
<gradient       //specify graident 
    android:startColor="#ffffffff" 
    android:endColor="#110000FF" 
    android:angle="90"/> 

<padding android:left="5dp" 
     android:top="5dp" 
     android:right="5dp" 
     android:bottom="5dp"/> 
<corners android:bottomRightRadius="7dp" 
     android:bottomLeftRadius="7dp" 
     android:topLeftRadius="7dp" 
     android:topRightRadius="7dp"/> 
</shape> 

<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="210dp" 
android:orientation="vertical" 
android:layout_marginBottom="10dp"   
android:background="@drawable/background"> 
関連する問題