Search code examples
androidxmllayoutscreen-orientationandroid-orientation

TextView does not appear on the device as it does on screen


It should appear on the device (as it is here in eclipse)

https://www.dropbox.com/s/72kxh2lpfja6wo0/CAM00049%5B1%5D.jpg

However it appears like this:

https://www.dropbox.com/s/b8efxqmarc0p15h/CAM00048%5B1%5D.jpg

...and I need the second TextView to appear centered as it does in the first screenshot.

SOURCE:

<?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="wrap_content"

    android:background="@drawable/background"
    android:orientation="vertical" >
  <TextView
      android:id="@+id/updated_text"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_alignParentTop="true"
      android:layout_marginTop="48dp"
      android:text="@string/updated_text2"
      android:textColor="#000000"
      android:textSize="22sp" />

  <TextView
      android:id="@+id/done_text"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@+id/updated_text"
      android:layout_centerHorizontal="true"
      android:text="@string/done_text"
      android:textColor="#000000"
      android:textSize="14sp" />

  <Button
      android:id="@+id/x_button"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@+id/done_text"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="61dp"
      android:background="@drawable/btn_close" />

</RelativeLayout>

Solution

  • Set the gravity on your lower TextView to center.

    android:gravity="center"