Android レイアウト 両端を揃える

Android レイアウト 両端を揃える場合、
LinearLayout orientation="horizontal" は、左→右方向に並べるので同じ行の中で
右→左にも配置をするには、工夫が必要だ。

layout_weight="1" を適切なところに配置する。
gravity を指定する。

サンプル

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    android:orientation="horizontal" >
    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:src="@drawable/ic_launcher" />
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="TextView" />
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        android:gravity="right" />
</LinearLayout>

f:id:posturan:20160314233658j:plain