0

I am trying to center a view but its not. The root container is a RelativeLayout. This only happens when phone is in Portrait orientation multi-window mode. I have tried putting the view in LinearLayout, RelativeLayout and FrameLayout but nothing works. I am amazed the same layout works when in landscape orientation multi-window mode.

 <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>

The TextView is positioned Top Left instead of centered horizontally. How can I make it work?

Ali
  • 839
  • 11
  • 21

1 Answers1

0

Change the width of the TextView used here to 'wrap_content' from 'match_parent'

GouravJn
  • 246
  • 1
  • 6
  • 18