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.

Jim Vitek
  • 4,174
  • 3
  • 23
  • 32

3 Answers3

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" />
Krylez
  • 17,414
  • 4
  • 32
  • 41
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.

emerssso
  • 2,376
  • 18
  • 24
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

Community
  • 1
  • 1
kevskree
  • 4,442
  • 3
  • 24
  • 32
  • 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 '14 at 17:09