I came across this link:
Declare the width of the width to half the width of the screen
How to do the same in relative layout? Here is the code: Try linearlayout inside the relative layout. But that does not work.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/bg" > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <Button android:id="@+id/button5" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="14dp" android:layout_weight="1" android:text="Button" /> <Button android:id="@+id/button6" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:layout_weight="1" android:text="Button" /> <Button android:id="@+id/button4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_weight="1" android:text="UID" android:textColor="#ffe5f1f1" /> <EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:background="#ffe5f1f1" android:hint="Enter UID" android:inputType="number" android:shadowColor="5" android:textColor="#ff009999" android:textStyle="bold" android:typeface="monospace" > <requestFocus /> </EditText> <Button android:id="@+id/button7" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:layout_alignParentLeft="true" android:layout_marginTop="18dp" android:text="Button" /> <Button android:id="@+id/button8" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/button7" android:layout_weight="1" android:layout_marginTop="16dp" android:text="Button" /> <Button android:id="@+id/button9" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:layout_alignParentLeft="true" android:layout_below="@+id/button8" android:layout_marginTop="17dp" android:text="Button" /> <EditText android:id="@+id/editText2" android:layout_width="50" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_weight="1" android:background="#ffe5f1f1" android:ems="10" android:hint="Enter Name" android:inputType="number" android:inputType="textPersonName" android:textColor="#ff009999" android:textStyle="bold" android:layout_weight="1" android:typeface="monospace" /> <EditText android:id="@+id/editText3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:ems="10" android:layout_weight="1" android:inputType="number" /> <EditText android:id="@+id/editText4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button7" android:layout_alignBottom="@+id/button7" android:layout_alignParentRight="true" android:ems="10" android:layout_weight="1" android:inputType="phone" /> <EditText android:id="@+id/editText5" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button8" android:layout_alignBottom="@+id/button8" android:layout_alignParentRight="true" android:ems="10" android:layout_weight="1" android:inputType="textPersonName" /> <RadioButton android:id="@+id/radioButton2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button9" android:layout_alignBottom="@+id/button9" android:layout_alignLeft="@+id/editText5" android:layout_weight="1" android:text="Male" /> <RadioButton android:id="@+id/radioButton1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/radioButton2" android:layout_alignBottom="@+id/radioButton2" android:layout_alignParentRight="true" android:layout_weight="1" android:text="Female" /> <Button android:id="@+id/button10" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/button9" android:layout_marginTop="31dp" android:layout_weight="1" android:text="Button" /> <Spinner android:id="@+id/spinDept" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button10" android:layout_alignBottom="@+id/button10" android:layout_alignLeft="@+id/radioButton2" android:layout_alignParentRight="true" android:layout_weight="1" android:background="#ff009999" /> </LinearLayout> </RelativeLayout>
source share