所以我在Android的佈局初學者,我正在學習RelativeLayout
。我試圖做出如下:Android佈局不如預期
然而,所有我在虛擬設備獲得的名稱是場佔用的空間(寬度和高度)的100%。
這裏是我的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>
到底哪裏出問題了?
爲什麼你將它嵌入到'LinearLayout'中? :-) –
用於使'方向'垂直。 'RelativeLayout'不支持'orientation'屬性。正如你所看到的,我只在'RelativeLayout'中添加了中間的'EditText',以便爲你的目的進行設計。頂端的「EditText」和底部的「Button」可以按照方向自動排列。如果您將移動設備的方向從縱向改爲橫向,那麼它也不會中斷。試着用這個xml做一些調整,它會讓你更好的主意。 – Anupam
和'-10'的重量是做什麼的? –