Android
Android レイアウト 中身が違っても均等な幅のボックスを作る
中々言葉で表現するのは難しいので、下記を見てほしいのですが、(弊社で開発しているSmart動態管理というソフトの一画面です)

下の部分の「到着」「休憩」は同じ文字数だからよいのですが、上の「空車」「積込済」というのは字数が違いますよね。
なので、ボタンの幅がそろわず、見た目がよくないです。
均等な幅を実現するために android:layout_weight というパラメーターがありますが、これを指定していても、android:layout_width=”wrap_content”などがあると、android:layout_widthの方が優先されてしまうんですね。
この部分のソースコードはこんな感じです。
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:paddingTop="10dp"
            android:paddingBottom="5dp" >
           <Button
	            android:id="@+id/vacant_button"
	            android:layout_width="wrap_content"
 	            android:layout_height="60dp"
                    android:layout_weight="0.5"
 	            android:text="@string/vacant"
	            android:textSize="24sp"
	            android:background = "@drawable/vacant_button"
	            android:layout_marginRight="5dp"
                     />
            <Button
	            android:id="@+id/occupied_button"
	            android:layout_width="wrap_content"
	            android:layout_height="60dp"
                    android:layout_weight="0.5"
	            android:text="@string/occupied"
	            android:textSize="24sp"
	            android:background = "@drawable/occupied_button"
                 />
         </LinearLayout>
android:layout_widthをなくすと、NullPointerEcceptionでエラーになります。
かといって、可変にしたいので、絶対的な大きさにもしたくない…
テーブルレイアウトは面倒…
そんな場合は、android:layout_width=”0dp”として回避しています。
    //変更後のソースコード
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:paddingTop="10dp"
            android:paddingBottom="5dp" >
 
           <Button
 	            android:id="@+id/vacant_button"
 	            android:layout_width="0dp"
 	            android:layout_height="60dp"
                    android:layout_weight="0.5"
                    android:text="@string/vacant"
 	            android:textSize="24sp"
 	            android:background = "@drawable/vacant_button"
 	            android:layout_marginRight="5dp"
 	             />
            <Button
 	            android:id="@+id/occupied_button"
 	            android:layout_width="0dp"
 	            android:layout_height="60dp"
                    android:layout_weight="0.5"
 	            android:text="@string/occupied"
 	            android:textSize="24sp"
 	            android:background = "@drawable/occupied_button"
                 />
  	    
        </LinearLayout>
修正後の画面はこんな感じになります。
