ビューのコンテンツが中央に配置されないのはなぜですか?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_gravity="center_vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/messageTextField"
android:layout_weight="1"
android:inputType="number"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/messageTextFieldPlaceholder"
/>
<Button
android:id="@+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sendButtonTitle"
android:onClick="sendMessage"
/>
</LinearLayout>
垂直方向の配置に関する SO スレッドをいくつか見ましたが、これも見ましたが、水平方向の LinearLayout しかないため、重力を設定するとビューが左右に調整されます。
LinearLayout は親の寸法を持っているので、画面全体を埋めませんか?
android:layout_gravity="center_vertical"
サブビューを寸法の中央 (垂直方向) に揃えるべきではありませんか?
これは、私が行ったコーディング全体で私にとって理にかなっているのですが、なぜアンドロイドが意味をなさないのですか?
その中に他のすべてを保持し、それを持っている垂直の別の LinearLayout が必要android:layout_gravity="center_vertical"
ですか?