Android stroke 邊框線 某一邊

weixin_34391854發表於2017-09-18

有時候需要給View加邊框線,我們經常是四邊一起加,就像這樣:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
       <solid android:color="#89c997"></solid>
       <stroke android:width="0.5dp" android:color="#c3c3c3"></stroke>
</shape>

然而有時候,我們並不需要四邊都會有邊框,那我們就需要用到layer-list標籤,比如我們只給下加邊框:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
     <item
         android:left="-2dp"
         android:right="-2dp"
         android:top="-2dp">
          <shape>
               <solid android:color="#ffffff"/>
               <stroke
                   android:width="1dp"
                   android:color="#ff0000"/>
          </shape>
     </item>
</layer-list>

在這個item中,你可以指定哪些邊不加邊框。

相關文章