Проблема гравитации в макете: android: layout_gravity = "end" - PullRequest
3 голосов
/ 14 июня 2019

Я новичок в изучении Android Studio и у меня возникли некоторые проблемы. в этом объяснении кода я должен видеть, как Hello World направлен вправо, но он не хочет двигаться слева. Вот что ожидается: ожидаемый результат и что я имею результат на данный момент .

<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:visibility="visible"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:gravity="center"
        android:text="Hello World!" />

</LinearLayout>

Ответы [ 3 ]

1 голос
/ 14 июня 2019

Добавьте android:orientation="vertical" к вашему LinearLayout. Ориентация по умолчанию горизонтальная.

0 голосов
/ 14 июня 2019

Попробуйте этот код: -

<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:visibility="visible"
android:orientation="horizontal">

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    android:gravity="end"
    android:text="Hello World!" />

</LinearLayout>
0 голосов
/ 14 июня 2019

Вы можете установить TextView 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:visibility="visible"
tools:context=".MainActivity"
orientation="horizontal">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    android:gravity="right"
    android:text="Hello World!" />

</LinearLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...