Monday, May 25, 2015

How to add a bottom border to RelativeLayout in Android

activity_main.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    tools:context=".MainActivity"
    android:background="@drawable/relative_layout_background"
    >
</RelativeLayout>
res/drawable/relative_layout_background.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <!-- draw a 4 dp width border around the rectangle shape -->
            <stroke android:color="#ffff0047" android:width="4dp"/>
        </shape>
    </item>
    <!--
        hide left, top and right side border using white color
        by padding 4 dp bottom side
    -->
    <item android:bottom="3dp">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white"/>
        </shape>
    </item>
</layer-list>
More android examples