How to Create Border in Relative Layout of Android

Here is the top answer to create border in Relative Layout in Android

Create a file called border.xml in your drawable folder:

<?xml version="1.0" encoding="UTF-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
   <corners android:radius="20dp"/> 
   <padding android:left="10dp" android:right="10dp" android:top="10dp" android:bottom="10dp"/>
   <stroke android:width="1dp" android:color="#CCCCCC"/>
 </shape>
RelativeLayout rectangle=new RelativeLayout(getContext());
        rectangle.setBackgroundColor(Color.BLUE);
        rectangle.setBackgroundResource(R.drawable.border);

Here is answer to add border in Android LinearLayout ?

<LinearLayout android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/customborder">

Leave a Comment