Monday, May 25, 2015

How to create a rounded corners 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"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <!-- solid background -->
            <solid android:color="#ffffba54"/>
            <!-- border-->
            <stroke
                android:color="#ffff206a"
                android:width="2dp"
                />
            <corners android:radius="25dp"/>
            <!-- different corners with different radius-->
            <!--corners
                android:bottomLeftRadius="5dp"
                android:topLeftRadius="10dp"
                android:topRightRadius="15dp"
                android:bottomRightRadius="20dp"
                /-->
        </shape>
    </item>
</selector>
More android examples