Почему не работает layout_gravity у LinearLayout?
Ничего не могу понять, в другом проекте атрибут layout_gravity работает, а в этом нет. Все компоненты остаются слева. Если для каждого компонента отдельно устанавливать свой gravity, то положение меняется, но хочется задать именно Linearlayout гравитацию, т.к. наполнения будет много и положение у всех будет одно
<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="vertical"
android:layout_gravity="center_horizontal"
tools:context=".WindowActivity"
>
<TextView
android:id="@+id/tv_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="40dp"
/>
<Button
android:id="@+id/b_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="@string/close" />
</LinearLayout>
Ответы (1 шт):
Автор решения: Style-7
→ Ссылка
Протестировал. Думаю сами в остальном разберетесь.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
>
<TextView
android:id="@+id/tv_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40dp"
android:text="TextView"
/>
<Button
android:id="@+id/b_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="Button" />
</LinearLayout>