画面を半分に割る

画面を右と左で半分ずつ使いたいことって多いですよね。


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <EditText
	    android:id="@+id/editText1"
	    android:layout_height="fill_parent"
	    android:layout_weight="1"
	    android:layout_width="0dip" />
    
    <EditText
	    android:id="@+id/editText2"
	    android:layout_height="fill_parent"
	    android:layout_weight="1"
	    android:layout_width="0dip" />
</LinearLayout>

layout_widthを0にして、layout_weightを同じ値にするのがポイント。

EditTextをLayoutにしてLayoutの入れ子にすればこんなことも

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <EditText
	    android:id="@+id/editText1"
	    android:layout_height="fill_parent"
	    android:layout_weight="1"
	    android:layout_width="0dip" />
    
    <LinearLayout
	    android:orientation="vertical"
	    android:layout_weight="1"
	    android:layout_height="fill_parent"
	    android:layout_width="0dip" >
	    
    <EditText
	    android:id="@+id/editText2"
	    android:layout_width="fill_parent"
	    android:layout_weight="1"
	    android:layout_height="0dip" />
    <EditText
	    android:id="@+id/editText3"
	    android:layout_width="fill_parent"
	    android:layout_weight="1"
	    android:layout_height="0dip" />
    </LinearLayout>
</LinearLayout>