Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

basics of device-independent-pixels

im throughoutly confused by dips on Android.

I understand from the reference that the base for dp values is 160. So, shouldn't 80dp in width equals a view with a width of 50% of the screen ? On my Nexus One the width in dp is something around 300dp as it seems.

What am i missing here ?

thx in advance

like image 327
user577708 Avatar asked Jan 16 '11 18:01

user577708


People also ask

What is a device-independent pixel used for?

Device-independent pixel. A device-independent pixel (also: density-independent pixel, dip, dp) is a unit of length. A typical use is to allow mobile device software to scale the display of information and user interaction to different screen sizes.

What is DPI (device-independent pixel)?

To program effectively with Windows graphics, you must understand two related concepts: Device-independent pixel (DIPs). Let's start with DPI. This will require a short detour into typography. In typography, the size of type is measured in units called points. One point equals 1/72 of an inch. This is the desktop publishing definition of point.

What are density independent pixels (DP) in Android?

Using constant values to define the sizes while designing the UI of an Android Application can sometimes lead to the app looking good on a few devices but looking jarring on some other devices. To avoid such issues, the Android team developed the concept of using Density Independent Pixels (dp, dip, sp) for defining sizes.

What is device independence?

Device Independence encompasses the techniques required to make such support an affordable reality. In particular the activity focuses on methods by which the characteristics of the device are made available for use in the processing associated with device independence


2 Answers

"dp" == "Density-independent Pixels" (This is also why it was earlier called "dip", though I prefer to use "dp" these days.)

Think of it like other units -- "in" (inches), "mm" (millimeters), etc. It allows you to provide a size that is scaled based on the density of the screen.

We define mdpi to be the base density, so "10dp" on an mdpi screen will result in exactly 10 pixels. On an hdpi screen it will result in 15 pixels, because hdpi is 1.5*mdpi.

Note that though the constants for various densities are similar to DPI (mdpi is 160, etc), density is not exactly DPI. It is an abstract scaling factor that adjusts for screen dpi, but does not try to exactly reflect it. (You would use "in", "mm", etc for exact sizes but 99.9% that is not what you want so stick with "dp".) This greatly simplifies life for everyone because you don't need to deal with many Android devices having a slightly different amount of space for its UI because they each of slight different screen DPIs. Also, device manufacturers can select the density of their device to achieve a desired UI -- for example the Samsung Tab uses a density that is a fair amount larger than the actual DPI, resulting in an overall larger UI.

like image 56
hackbod Avatar answered Sep 22 '22 23:09

hackbod


160 dots per inch. So 80dp would be 1/2 an inch, roughly.

like image 38
Kevin Coppock Avatar answered Sep 20 '22 23:09

Kevin Coppock