4

Which measurement we should use in Android: px, dp, dip or sp ???

Is there any percentage kind of thing in android layout design as we have in CSS for web development.

Which measurement is safe to use in Android to design cross phone compatibility.

Undo
  • 25,519
  • 37
  • 106
  • 129
Vins
  • 8,849
  • 4
  • 33
  • 53
  • 1
    Refer link: http://stackoverflow.com/questions/2025282/difference-of-px-dp-dip-and-sp-in-android – NguyenDat Jun 22 '11 at 02:11
  • I think you need this : http://stackoverflow.com/questions/2025282/difference-between-px-dp-dip-and-sp-in-android – AsmaG Jul 04 '14 at 11:08

4 Answers4

5

dip is best used for when you need something a static size. This is a "Device Independant Pixel" and will roughly be rendered the same physical size on any handset/tablet.

Ideally though, you should be using layout_weights and clever implementations of match_parent and wrap_content to fill most fields.

Edit: Just FYI, dip = dp ... compiler handles them equivocally. Use whichever you like.

Eric
  • 1,953
  • 4
  • 24
  • 33
  • 1
    Is there any ways to divide my screen in to 74% and 2% gap and 24%, can you give xml for this kind of layout? Which will appear on uniformly on all the device. Thanks!! – Vins Jun 09 '11 at 03:40
  • 1
    If you wanna do it like that set one views layout_weight to 74, a middle view to 2, and third view to 24. Make sure each of them have the same exact value for layout_width or layout_height (whatever it is that you are trying to assign) – Eric Jun 09 '11 at 04:32
2
  1. The canned answer would be use dp for layouts and sp for font sizes.
  2. The only percentage layout mechanism is layout_weight used with linear layouts.
  3. See answer #1.
Nick Campion
  • 10,479
  • 3
  • 44
  • 58
1

dip == dp use dp for all the resources as it renders a/c to screen resolution . and use sp for font size instead px as sp works w.r.t screen size and resolution .

Furqan
  • 465
  • 6
  • 22
1

It's way too late now to answer but just to help someone else like me..

layout_constraintHorizontal_bias or layout_constraintVertical_bias to set layout by percentage after connecting it to the edges.

44yu5h
  • 111
  • 5