いくつかの異なることができます。前述のように、レイアウトにはピクセルではなく dp を使用する必要があります。dp を使用すると、ビューを解像度ではなく画面の物理サイズでスケーリングできます。
各ラベルの右側に表示され、画面の残りの部分を占めるように編集ボックスを指定する例を次に示します。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/name_label"
android:layout_width="100dp"
android:layout_height="50dp"
android:text="Name:" />
<TextView
android:id="@+id/phone_label"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_below="@id/name_label"
android:text="Phone:" />
<EditText
android:id="@+id/name_text"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_toRightOf="@id/name_label" />
<EditText
android:id="@+id/phone_text"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_toRightOf="@id/phone_label"
android:layout_below="@id/name_text" />
</RelativeLayout>
重みが使用されている LinearLayout の例を次に示します。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="Name:"
android:layout_weight="1"/>
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="Phone:"
android:layout_weight="1"/>
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"/>
</LinearLayout>
</LinearLayout>
LinearLayout には 7 つのビューがあり、RelativeLayout には 5 つのビューで同様のことが行われていることに注意してください。LinearLayouts は便利ですが、より複雑です。レイアウトが複雑になると、特にネストした場合に、RelativeLayouts よりもパフォーマンスが低下します。