Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android why text size is different for all devices even if one text size in sp is specified?

I'm wondering why my TextView size is different for different devices even if I set the text size in sp or dp.

Please help me. Thanks.

like image 224
migs Avatar asked Sep 30 '14 13:09

migs


People also ask

Should Use SP instead of dp for text sizes?

When setting text sizes, you should normally use sp , or “scale-independent pixels”. This is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and the user's preference.

What is default text size in Android?

You should think of this as the normal font size, and basically everything else a variation on it. For instance, while 14sp is the default text size when the text can be quite long, when there's only a small modal with a bit of text, it's 16sp! Notice that it's a bit lighter to make up for this size boost.

Why is my text font so big Android?

Open your device's Settings app. Tap Accessibility, then tap Display size. Use the slider to choose your display size.


1 Answers

This post explains the difference:

dip/dp (density independent pixels):

an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".

sp (scale independent pixels):

like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.

And this post explains why dp and sp values may differ:

The dp has constant ratio transition to pixels: dp = px * ratio. Ratio will never change on any particular device.

The sp has scalable ratio: sp = px * ratio * scale. Ratio never changes, but scale is user configurable. This scale can be used by people who need larger font sizes, for example, to use device more comfortably.

like image 61
Tadej Avatar answered Nov 14 '22 23:11

Tadej