2

Why does text of x size not fit within a TextView of that same size?

For example, this TextView:

<TextView
    android:id="@+id/time"
    android:layout_width="wrap_content"
    android:layout_height="60dp"
    android:padding="0dp"
    android:textSize="60dp"
    android:text="12:22" />

Renders like this on my Nexus 5: enter image description here

I'm not asking for how to scale the text (like many other questions). I am just trying to understand why android does this, and a formula for enough buffer to avoid clipping.

3 Answers 3

2

It should help to disable the implicit font padding

<TextView
    android:id="@+id/time"
    android:layout_width="wrap_content"
    android:layout_height="60dp"
    android:drawablePadding="0dp"
    android:padding="0dp"
    android:textSize="60dp"
    android:includeFontPadding="false"
    android:text="12:22" />
0
0

I think this tool may be helpful for you. It allows you to translate various UI units, like SP to DP. Seems like you should be able to figure out the correct conversions for various screen densities.

0
0

The unit sp can be changed in settings by the user to be different sizes. If you need the text to fit inside a bounding box you should use dp as the unit.

See Android sp vs dp

1
  • Nice informative link, but it doesn't totally answer the question. I changed textSize to 60dp and the clipping still occurs just as it did when I tried sp with 'Normal' size text in Settings->Display->Font size. I will change the question to dp in honor of your very good observation :)
    – Jim Vitek
    Sep 24, 2014 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.