0

I try to make XML layout from PSD file. Right now PSD file have dimensions 320x1440. I have read on android.developers that mdpi (160dpi) have resolution 320x480. So I is assumed that in that case 1px in my PSD file is equal to 1dp. Thats the theory.

But I spotted little differences - especially in font sizes. For example I in the project some font have 24px size I need to divide it by 2 (like 320dpi but PSD file is 320px). Also if I have element which is 300px height in my PSD file it is not 300dp in android studio.

I have tried to google answer but had no luck. Any help is much appreciated.

Glorifind
  • 402
  • 6
  • 20

1 Answers1

5

From this answer:

  • px is one pixel.
  • sp is scale-independent pixels.
  • dip is Density-independent pixels. enter image description here

You would use

  • sp for font sizes

  • dip for everything else.

    dip==dp

From Android Developers center:

px
Pixels - corresponds to actual pixels on the screen.

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

mm
Millimeters - based on the physical size of the screen.

pt (it depends upon physical size of the screen) Points - 1/72 of an inch based on the physical size of the screen.

This will help you for more understanding.

enter image description here

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 - 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 user's preference.

Community
  • 1
  • 1
Mou
  • 2,027
  • 1
  • 18
  • 29