Add Only Top And Bottom Border On Linearlayout
I would like to add only a bottom and a top border on my Linearlayout. I have tried to do this : Copy
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.
Solution 2:
Make this two file and put this code. you can set border top and bottom border,
main.xml
<TextViewandroid:text="This is textline"android:background="@drawable/border_set"
/>
border_set.xml
This file located into full path project_root/res/drawable/border_set.xml
<?xml version="1.0" encoding="utf-8"?><layer-listxmlns:android="http://schemas.android.com/apk/res/android" ><item><shapeandroid:shape="rectangle"><strokeandroid:width="1dp"android:color="#FF000000" /><solidandroid:color="#FFDDDDDD" /></shape></item><itemandroid:top="1dp"android:bottom="1dp"><shapeandroid:shape="rectangle"><strokeandroid:width="1dp"android:color="#000" /><solidandroid:color="#FFFFFF" /></shape></item></layer-list>
Solution 3:
Here is the solution. It works even with transparent background.
<?xml version="1.0" encoding="utf-8"?><layer-listxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:left="-2dp"android:right="-2dp"><shapeandroid:shape="rectangle"><strokeandroid:width="2dp"android:color="@color/borderColor" /><solidandroid:color="@color/backgroundColor" /></shape></item></layer-list>
Solution 4:
I believe this is the simplest way:
<Viewandroid:layout_width="match_parent"android:layout_height="2dp"android:background="#000000" />
Solution 5:
This is my version; top border and bottom border are visible, not showing the left or right borders. And the background is transparent.
<?xml version="1.0" encoding="utf-8"?><layer-listxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="1dp"><itemandroid:left="-1dp"android:right="-1dp"android:top="-1dp"android:bottom="1dp"><shapeandroid:shape="rectangle"><strokeandroid:width="1dp"android:color="@color/BlueGrey_colorPrimary" /><solidandroid:color="@android:color/transparent" /></shape></item></layer-list>
Post a Comment for "Add Only Top And Bottom Border On Linearlayout"