1

这是屏幕截图 在这里,当我使用 layout_centerHorizo​​ntal 时,它可以正常工作,但是每当我使用 layout_centerVertical 时,它就无法正常工作。我该如何解决这个问题?

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FF4081">

    <TextView
        android:text="Have a nice day"
        android:layout_centerHorizontal="true"
        android:textColor="#FFFFFF"
        android:textSize="25sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</RelativeLayout>
4

1 回答 1

0

你应该试试这个,它适用于 Android 工作室,文本视图将垂直居中在父级的右侧:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FF4081">

    <TextView
        android:text="Have a nice day"
        android:textColor="#FFFFFF"
        android:layout_centerVertical="true"
        android:layout_alignParentRight="true"
        android:textSize="25sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

</RelativeLayout>
于 2018-06-17T11:34:27.833 回答