Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show only top and bottom border

This is my XML code which works fine, the only problem is it's showing border on all four sides while I want only to show border on the top and on the bottom only. How can I do that?

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#FFFFFF" />
    <stroke
        android:width="3dip"
        android:color="#B1BCBE"
    />

    <padding
        android:bottom="0dip"
        android:left="0dip"
        android:right="0dip"
        android:top="0dip"
    />

</shape>
like image 608
user2761245 Avatar asked Sep 10 '13 12:09

user2761245


People also ask

How do you just get the top and bottom border?

You can use the border-left , border-right , border-top and border-bottom properties to give different border styles to each side of your container. In your case, you want to apply your style to border-top and border-bottom .


2 Answers

Try the below

<?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" >  
     // add android:right="5dp" and android:left="5dp" for border on left and right
     <shape android:shape="rectangle"> 
      <solid android:color="#000000" />
    </shape>
   </item>    
 </layer-list> 

enter image description here

Edit:

Modify the below according to your requirements by changing the color, stroke width and padding

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

Snap

enter image description here

like image 152
Raghunandan Avatar answered Sep 30 '22 16:09

Raghunandan


use:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 <!-- Describes the line -->
    <item android:top="-1dp" android:bottom="-1dp">
        <shape>
            <solid android:color="@android:color/transparent" />
            <stroke android:width="1dp" android:color="#ffffff" />
        </shape>   
    </item>
</layer-list>
like image 26
Daniel L. Avatar answered Sep 30 '22 17:09

Daniel L.