Я новичок в изучении 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>
Добавьте android:orientation="vertical" к вашему LinearLayout. Ориентация по умолчанию горизонтальная.
android:orientation="vertical"
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" 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>
Вы можете установить 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>