2013-07-08 187 views
0

其實我有這樣的代碼:BackgroundResource邊框的頂部和底部

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" > 
    <solid 
     android:color="#ffffff" /> 
    <stroke 
     android:width="0.5dp" 
     android:color="#000000" /> 
</shape> 

它創建圍繞視圖中的邊界,但我只想做一個邊框的頂部和底部。

怎麼樣?

編輯:對不起,我忘了應該與工作狀態下按下

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item 
     android:state_pressed="true" 
     android:drawable="@color/color" /> 
</selector> 
+0

http://stackoverflow.com/questions/9211208/how-to-draw-border-on-just-one-側的-A-線性佈局。試試這個 – Raghunandan

+0

@Raghunandan謝謝 – user222

+0

你可以查看下面的文章清晰度 – Raghunandan

回答

1

嘗試在繪製文件夾這個

bkg.xml

<?xml version="1.0" encoding="utf-8"?> 
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
    <shape android:shape="rectangle"> 
     <solid android:color="#FF0000" /> 
    </shape> 
    </item> 
    <item android:bottom="5dp" android:top="5dp" > 
    <shape android:shape="rectangle"> 
     <solid android:color="#000000" /> 
    </shape> 
    </item>  
</layer-list> 

更改顏色和行程寬度根據您的要求。圖形編輯器

enter image description here

編輯的

快拍:爲了這個問題在評論

定義itembkg。 XML如下

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="true" 
     android:drawable="@drawable/bkg" /> 
     // bkg.xml in drawable folder 
     // drawable in pressed state 
    <item android:state_focused="false" 
     android:drawable="@drawable/tvnormal" /> 
     // set a different drawable in normal state 
</selector> 

然後在您的視圖中添加以下屬性

android:background="@drawable/itembkg" 
+0

我怎樣才能將這與狀態按下? – user222

+0

我無法正常工作 – user222

+0

@ user222檢查編輯。它適用於我我已經嘗試發佈前 – Raghunandan

0

試試這個....

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

     <padding android:top="1dp" 
       android:bottom="1dp" /> 
     <solid android:color="#000000"/> 


    </shape> 
    </item> 
    <item > 
    <shape android:shape="rectangle"> 

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

    </shape> 
</item> 
</layer-list> 
相關問題