Arbaz Alam Arbaz Alam - 23 days ago 8
Android Question

How to draw a rectangle box around elements of Android Activity?

I want to create a rectangle box around the elements as shown in figure. Two edittext fields and a button should inside the box and outside of box is list. How can I achieve this. Kindly answer in detail because I am new in Android programming.

enter image description here

Answer

create a xml file in drawable like below and set it as background for your view

rectanglebg.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/listview_background_shape">
    <stroke android:width="2dp" android:color="#FF0000" />
    <padding android:left="2dp"
        android:top="2dp"
        android:right="2dp"
        android:bottom="2dp" />
    <corners android:radius="5dp" />
    <solid android:color="#ffffffff" />
</shape>