1

I am a beginner in android, I have a basichat doubt For setting font size what is most preferred in android sp, px or pt. Any help will appreciate

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
  • This question might help: https://stackoverflow.com/questions/2025282/what-is-the-difference-between-px-dp-dip-and-sp-on-android – TuringTux May 29 '17 at 05:27
  • 1
    Possible duplicate of [What is the difference between "px", "dp", "dip" and "sp" on Android?](https://stackoverflow.com/questions/2025282/what-is-the-difference-between-px-dp-dip-and-sp-on-android) – TuringTux May 29 '17 at 05:28
  • This is a duplicate of https://stackoverflow.com/questions/23981260/should-use-sp-instead-of-dp-for-text-sizes – EKN May 29 '17 at 06:52

5 Answers5

2

sp: Scale Independent Pixel, scaled based on user’s font size preference.Fonts should use sp.
sp is preferrable for setting font size.

Nithya
  • 42
  • 8
0

Sp. Sp is scaled pixels. It scales with the text size the user sets. This means that people with problems seeing can set a larger base font size, and your text will scale with that setting. It makes it easier for those people to use the app.

Gabe Sechan
  • 84,451
  • 9
  • 82
  • 121
0

SP Scale-independent Pixels

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

for Refrence more

Ratilal Chopda
  • 4,113
  • 4
  • 17
  • 29
0

px

Pixels - corresponds to actual pixels on the screen.

in

Inches - based on the physical size of the screen. 1 Inch = 2.54 centimeters

pt

Points - 1/72 of an inch based on the physical size of the screen.

dp or dip

  1. Density Independent Pixel, it varies based on screen density . In 160 dpi screen, 1 dp = 1 pixel. Except for font size, use dp always
  2. 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 - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommended you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.

for more information Android Developer Documentation:

or click here

AskNilesh
  • 63,753
  • 16
  • 113
  • 150
0

Sp for font size

dp for any view width, height, margin, padding etc.

px not recommended in android development

for more detail read this

Mukesh Y.
  • 819
  • 1
  • 14
  • 35