Set rounded corner radius border to relativelayout android

How to apply smooth plain rounded stroke on whole complete RelativeLayout using external layout xml file.

Adding border to whole relative layout using external custom made xml file is very easy process. So my here is the complete step by step tutorial for Set rounded corner radius border to relativelayout android.

android-project-download-code-button

How to Set rounded corner radius border to relativelayout android.

What we are doing in this project : We are creating an external relativelayout_radius_border.xml file inside layout folder and setting up that particular layout file as background of relativeLayout inside activity_main.xml file using android:background=”@layout/relativelayout_radius_border” attribute.
Code for MainActivity.java file.

package com.relativelayoutborder_android_examples.com;
import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }
}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.relativelayoutborder_android_examples.com.MainActivity"
 android:background="@layout/relativelayout_radius_border" >

 <TextView
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:text="Relative Layout with Rounded radius border"
 android:textAppearance="?android:attr/textAppearanceLarge"
 android:gravity="center" />

</RelativeLayout>

Code for relativelayout_radius_border.xml file.

 <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
 <shape android:shape="rectangle">
 
 <solid android:color="#fdfcfc"/>
 
 <stroke
 android:color="#01e9fe"
 android:width="2dp"
 />
 
 <corners android:radius="41dp"/>
 </shape>
</item>
</selector>

Screenshot:

Set rounded corner radius border to relativelayout android

Click here to download Set rounded corner radius border to relativelayout android project.

Leave a Reply

Your email address will not be published. Required fields are marked *