我學習相對佈局,並寫了一個小測試佈局模擬登錄頁面:的Android RelativeLayout的怪異行爲
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<TextView android:id="@+id/labelUsername"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="username:"
android:layout_centerVertical="true"/>
<EditText android:id="@+id/txtUsername"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:hint="input username here"
android:layout_toRightOf="@id/labelUsername"
android:layout_alignBaseline="@id/labelUsername"/>
<TextView android:id="@+id/labelPassword"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="password:"
android:layout_below="@id/txtUsername"
android:layout_alignParentLeft="true"/>
<EditText android:id="@+id/txtPassword"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:hint="input password here"
android:layout_below="@id/txtUsername"
android:layout_alignLeft="@id/txtUsername"
android:layout_alignBaseline="@id/labelPassword"/>
</RelativeLayout>
我要的是把Username Label
和Textfield
的Password Label
和TextField
上面有什麼。但結果被還原,密碼在上面!
我認爲這個問題是「機器人:layout_below」在labelPassword
屬性,如果我將它設置爲低於labelUsername
,它的工作原理,但由於textfield
比標籤更大,兩者textfields
在這種情況下覆蓋。所以我儘量使labelPassword
低於txtUsername
,但它表現奇怪,我不明白。
順便說一句,當我使用相對佈局構建佈局時,是否有任何指導原則?
我應該先在那裏放什麼?
我最後應該放什麼?
謝謝!
爲什麼使用相對佈局當這顯然是tablelayout的一項工作? – Merlin