0

enter image description here

I want the controller textView to be centre of the app. I used android:gravity="center" but doesn't help. My code is

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
   >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CONTROLLER"
        android:textSize="30dp"
        android:gravity="center"
        android:textColor="#fff"
        android:layout_marginTop="39dp"
        android:id="@+id/textView3"
        />
    </LinearLayout>

Thanks in advance for helping.

SibhiRajan
  • 45
  • 1
  • 1
  • 5

1 Answers1

1

Just android:gravity="center" in the Layout and also android:layout_height="match_parent"to the center the TextView in the whole View. and android:gravity="center_horizontal" to centralize it horizontaly.

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center" >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CONTROLLER"
        android:textSize="30sp"
        android:textColor="#fff"
        android:layout_marginTop="39dp"
        android:id="@+id/textView3"
        />
</LinearLayout>

and also the textSize should be meausured in sp not dp.

Ahmed Hegazy
  • 12,395
  • 5
  • 41
  • 64