2012-12-11 169 views
4

這是我的編碼。這是爲TextView的4邊框設計的藍色。我想要的只是設計3個邊框(頂部,左側和底部)。如何僅爲TextView的左邊,頂部和底部邊框

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="true" > 
     <shape> 
      <solid 
       android:color="#449def" /> 
      <stroke 
       android:width="1dp" 
       android:color="#2f6699" /> 
      <corners 
       android:radius="0dp" /> 
      <padding 
       android:left="5dp" 
       android:top="5dp" 
       android:right="5dp" 
       android:bottom="5dp" /> 
     </shape> 
    </item> 
    <item> 
     <shape> 
      <gradient 
       android:startColor="#ffffff" 
       android:endColor="#ffffff" 
       android:angle="270" /> 
      <stroke 
       android:width="1dp" 
       android:color="#2f6699" /> 
      <corners 
       android:radius="0dp" /> 
      <padding 
       android:left="5dp" 
       android:top="5dp" 
       android:right="5dp" 
       android:bottom="5dp" /> 
     </shape> 
    </item> 
</selector> 
+0

http://stackoverflow.com/questions/5254562/is-there-a-simpler-better-way-to-put-a-border-outline-around-my -textview – RobinHood

回答

2

這是一個快速的解決方案(可能是愚蠢的),在你的TextView上加android:translationX="2dp",你可以添加android:paddingRight="2dp"來彌補失落的空間。

8

下面的代碼放置在1DP的高度的底部,你玩這個的其他各方

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

<!-- This is the line --> 
<item> 
    <shape> 
     <solid android:color="#535353" /> 
    </shape> 
</item> 

<!-- This is the main color --> 
<item android:bottom="1dp"> 
<shape> 
     <solid android:color="#252525" /> 
</shape> 
</item> 
</layer-list> 

參考討論Open-sided Android stroke?

+1

線和主要顏色是不同的,你給的鏈接,我認爲你是錯誤的。評論應該改變 –

1

嘗試這樣

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape> 
      <padding android:bottom="1dp" android:left="1dp" android:right="0dp" 
       android:top="1dp"/> 
      <solid android:color="#000"/> 
     </shape> 
    </item> 

    <!-- Background --> 
    <item> 
     <shape> 
      <solid android:color="@color/white"/> 

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