私の要件は、LinearLayout でこれを達成することです。子ビューが 1 つしかありません。水平方向では、layout_gravity が設定されている場合、ボタンを水平方向の中央に配置する必要があります。私のレイアウトxmlは
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="200dp"
android:background="#ffff00"
android:layout_width="match_parent"
android:orientation="horizontal">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Button" />
</LinearLayout>
しかし、結果は下の画像のようになります
私が期待しているのは、layout_gravity が center_horizontal に設定されている場合、ボタンの中心が水平になることです。これが機能しない理由