<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/buttonClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click"
android:layout_alignParentLeft="true" />
<Button
android:id="@+id/buttonShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Share"
android:layout_alignParentRight="true" />
</RelativeLayout>
layout_alignParentLeft="true":左按鈕貼左邊。layout_alignParentRight="true":右按鈕貼右邊。LinearLayout + layout_weight="1" 平均分配,或 layout_toLeftOf="@id/buttonShare" 使左按鈕右邊對齊右按鈕左邊。<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/buttonClick"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Click" />
<Button
android:id="@+id/buttonShare"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Share" />
</LinearLayout>
兩按鈕各佔 50% 寬度,緊密相連無間隙。