Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add only top and bottom border on LinearLayout [duplicate]

Tags:

I would like to add only a bottom and a top border on my Linearlayout. I have tried to do this :

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

But it add a border around the shape..

Could you help me please ?

like image 595
wawanopoulos Avatar asked Apr 22 '14 10:04

wawanopoulos


People also ask

How do you overlap a linear layout?

How do you overlap a linear layout? By assigning margin value "<0" we can overlap the views. But Relative layout is preferable when we need o overlap views. Save this answer.

Is LinearLayout a Viewgroup?

LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute.


1 Answers

I think you can create this drawable and use it as background:

<?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="#000"/>         </shape>     </item>     <item android:bottom="1dp" android:top="1dp">         <shape android:shape="rectangle" >             <solid android:color="#FFFFFF" />         </shape>     </item> </layer-list> 

Think of is as drawing a rectangle with border color first and then lay on top of it a rectangle with your background color leaving out 1dp on top and at the bottom.

like image 122
Tony Vu Avatar answered Sep 16 '22 11:09

Tony Vu