Я попытался наложить текст в верхнем центре, но не смог
Я проверил Этот вопрос , но ответ не получился
Я попытался
<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" />
Это то, что я получаю после запуска на эмуляторе, который не центрирован
Попробуйте это:
<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>
добавьте это в ваш RelativeLayout
RelativeLayout
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Welcome" android:layout_centerHorizontal="true"/>
Просто используйте android:layout_centerInParent="true" в вашем TextView
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>