Android: Using the GUI editor to change text size

I found it a bit baffling when I entered in a number into the text-size field and the control just disappeared. At first I was annoyed, wandering why such a stupid feature wasn't tested properly.

Then when I looked it up, I realised it needed a little bit more information from me. The way that text resizing on the user interface was implemented in Android was intended to be flexible, and inherently a little more complicated.

The text-size attribute (much like margin and padding attributes) require values and units.

If you enter in "20px", it'd be a fixed 20 pixel size. Not quite helpful when you work with various pixel densities and screen sizes.

A much more suitable measurement unit would be "20sp", which is 20 density independant pixels (dips), but scaled to suit the user's font size settings.

There are other units such as:

  • in (inches)
  • mm (millimeters)
  • pt (point - font size)
  • dp (density independant pixels)
  • sp (density independant pixels, scaled to user's font size preferences)

Alot of tutorials will focus mainly on px and dp, which aren't entirely the best way of going about creating a multi-device compatible code.

Sources

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog