0

我正在尝试使视图居中,但事实并非如此。根容器是一个RelativeLayout。这只发生在手机处于纵向多窗口模式时。我尝试将视图放在 LinearLayout、RelativeLayout 和 FrameLayout 中,但没有任何效果。我很惊讶在横向多窗口模式下相同的布局可以工作。

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/root_relative"
    android:background="@color/colorAccentWhite"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true"
    android:clickable="true">

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center">

        <TextView
            android:id="@+id/name_textview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="17sp"
            android:textColor="@color/black"
            android:visibility="invisible" />

    </RelativeLayout>

</RelativeLayout>

TextView 位于左上而不是水平居中。我怎样才能让它工作?

4

1 回答 1

0

将此处使用的 TextView 的宽度从 'match_parent' 更改为 'wrap_content'

于 2017-11-03T20:54:37.067 回答