Android выровнять текст вверху по центру не удается - PullRequest
0 голосов
/ 19 декабря 2018

Я попытался наложить текст в верхнем центре, но не смог

Я проверил Этот вопрос , но ответ не получился

Я попытался

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".OnboardingActivity">

<TextView
    android:layout_alignParentTop="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:text="Welcome"
    />

Это то, что я получаю после запуска на эмуляторе, который не центрирован

enter image description here

Ответы [ 3 ]

0 голосов
/ 19 декабря 2018

Попробуйте это:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:gravity="center"
        android:text="Welcome" />

</LinearLayout>
0 голосов
/ 19 декабря 2018

добавьте это в ваш RelativeLayout

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:text="Welcome"
        android:layout_centerHorizontal="true"/>
0 голосов
/ 19 декабря 2018

Просто используйте android:layout_centerInParent="true" в вашем TextView

Попробуйте это

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".OnboardingActivity">

<TextView
    android:layout_alignParentTop="true"
    android:layout_width="wrap_content"
    android:layout_centerInParent="true"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="Welcome"
    />

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