Search code examples
androidfontstextviewgravity

Gravity being ignored over a certain textsize


Am I missing something, if I just have a standard TextView and set its text size over a set number the gravity to center the text stops working, see below example.

Gravity working:

 <TextView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:text="B"
    android:textSize="472sp" />

Gravity working


Gravity not working

 <TextView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:text="B"
    android:textSize="572sp" />

Gravity not working

This happens on a device as well as the emulator / preview.


Solution

  • I would have guessed it's because the total size of the TextView including implicit padding (such as may exist) is simply larger than your screen, so the field is pinned at the top and the visible portion is forced down the screen. What happens if you put it onto a bigger display? Edit: In the 572sp example, it comes pretty close to centered in portrait mode on a tablet.