Skip to content

Instantly share code, notes, and snippets.

@Antarix
Created February 3, 2013 14:53
Show Gist options
  • Save Antarix/4702083 to your computer and use it in GitHub Desktop.
Save Antarix/4702083 to your computer and use it in GitHub Desktop.
Setting specific border i.e top,bottom,left,right or all for Android layout
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
android:shape="rectangle">
<!-- Set the border color of your layout here -->
<stroke android:width="1dp" android:color="#3AFB03" />
<solid android:color="#3AFB03" />
</shape>
</item>
<!-- This is for border bottom but
you can change this according to your need -->
<item android:bottom="4dp" >
<shape
android:shape="rectangle">
<!-- Set the background color of your layout here -->
<stroke android:width="1dp" android:color="#000000" />
<solid android:color="#000000" />
</shape>
</item>
</layer-list>
@faizalumer
Copy link

this is awesome. but i am wondering why would you use a bottom offset value of 4dp for the top layer, when the border width is only 1dp?

@sumitlahade
Copy link

How to give margins from left and right to the border? I don't want border to be end to end. Is there any solution ?

@Guang1234567
Copy link

@sumitlahade

Hope it help you!

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape
            android:shape="rectangle">
            <!-- Set the border color of your layout here -->
            <solid android:color="#3AFB03" />

        </shape>
    </item>

    <!-- This is for border bottom but
    you can change this according to your need -->
    <item android:right="4dp" >
        <shape
            android:shape="rectangle">
            <!-- Set the background color of your layout here -->
            <solid android:color="#000000" />
        </shape>
    </item>

</layer-list>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment