Reputation: 24998
So I am a beginner at layouts in Android and I am learning RelativeLayout
. I am attempting to make the following:
However, all I get in my virtual device is the name field taking up 100% of the space (width and height).
Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/root">
<EditText android:id="@+id/name"
android:layout_alignParentLeft="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint = "Name"/>
<EditText android:id="@+id/phone"
android:layout_below="@id/name"
android:layout_alignParentRight="true"
android:layout_weight="0.4"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:hint="Phone" />
<EditText android:id="@+id/email"
android:layout_below="@id/phone"
android:layout_alignParentRight="true"
android:layout_weight="0.4"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:hint="Email" />
<EditText android:id="@+id/dob"
android:layout_below="@id/email"
android:layout_alignParentRight="true"
android:layout_weight="0.4"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:hint="D.O.B." />
<EditText android:id="@+id/address"
android:layout_below="@id/phone"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/dob"
android:layout_weight="0.6"
android:layout_height="0dp"
android:layout_width="match_parent"
android:hint="Address" />
<Button android:id="@+id/submit"
android:layout_weight="1.0"
android:layout_below="@id/address"
android:layout_height="match_parent"
android:layout_width="0dp"
android:text="Submit"/>
</RelativeLayout>
What is going wrong?
Upvotes: 0
Views: 88
Reputation: 4341
Change your Layout XML to the above:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:hint="Name" />
<LinearLayout
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/name"
android:orientation="horizontal"
android:layout_marginBottom="60dp"
android:weightSum="1" >
<EditText
android:id="@+id/address"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:hint="Address" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.4"
android:weightSum="3" >
<EditText
android:id="@+id/phone"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="Phone" />
<EditText
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="Email" />
<EditText
android:id="@+id/dob"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="D.O.B." />
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/submit"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:text="Submit" />
</RelativeLayout>
Hope that helps:)
Upvotes: 1
Reputation: 3752
Here is the xml for your output.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:hint="Name" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true
android:layout_weight="-10"
android:hint="Phone" />
<EditText
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/phone"
android:layout_weight="0.4"
android:hint="Email" />
<EditText
android:id="@+id/dob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/email"
android:layout_weight="0.4"
android:hint="D.O.B." />
<EditText
android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/phone"
android:layout_toLeftOf="@id/dob"
android:layout_weight="0.6"
android:hint="Address" />
</RelativeLayout>
<Button
android:id="@+id/submit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Submit" />
</LinearLayout>
Upvotes: 2
Reputation: 949
Change the layout_height for the name element to:
android:layout_height="wrap_content"
Upvotes: 1