Android supports several units of measurement for designing interfaces, including pixels (px), inches (in), millimeters (mm), points (pt), density-independent pixels (dp), and scale-independent pixels (sp). Dp units are based on a 160 dpi screen density and scale with screen density, while sp units also factor in the user's font size preferences. For example, a 0.5x0.5 inch icon at the highest supported density of 480 dpi would be 240x240 pixels. Resources can be placed in density-specific folders and referenced using a naming system to support different screen densities.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
61 views9 pages
Mobile Computing: Android Unit of Measurement
Android supports several units of measurement for designing interfaces, including pixels (px), inches (in), millimeters (mm), points (pt), density-independent pixels (dp), and scale-independent pixels (sp). Dp units are based on a 160 dpi screen density and scale with screen density, while sp units also factor in the user's font size preferences. For example, a 0.5x0.5 inch icon at the highest supported density of 480 dpi would be 240x240 pixels. Resources can be placed in density-specific folders and referenced using a naming system to support different screen densities.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9
Mobile Computing
Android Unit Of Measurement
Android supports the following measurements • px (Pixels) - Actual pixels or dots on the screen. • in (Inches) - Physical size of the screen in inches. • mm (Millimeters) - Physical size of the screen in millimeters. • pt (Points) - 1/72 of an inch. • 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. "dip" and "dp" are same. • sp (Scale-independent Pixels) - Similar to dp unit, but also scaled by the user's font size preference. Density Bucket More Dpi Dense Pixels Scaling With Screen Density Example For example, say an icon is intended to be 0.5x0.5 in when rendered on a screen. Next, the image must be created at the largest density supported, or as a scalable vector graphic. Best practice is to support the maximum density, which currently is xxhdpi at 480 dpi. At 480 dpi, a 0.5x0.5 in image converts to 240x240 px Once all versions have been created, they can be added to "drawable" folders, using resource identifiers to tell Android what density bucket they are intended for. Last, simply reference the graphic resource in xml layouts and code using its name generated in the "R" file, which holds references to all resources in the app. Android will then load the resources at runtime, doing its best to match the actual device's configuration to the resource identifiers applied. Example-Pixel Size Dp Magic Dp Magic • The reason "dp" tends to vary in physical size is due to the same scaling factor being applied for the entire density bucket. The scaling factor is computed with the density bucket's dpi, and not the device's actual dpi. When the device's dpi is not exactly the same as its density bucket's dpi, the same amount of "dp" converts to the same amount "px". This leads to the same amount of "px" being displayed on different density screens, which render at different sizes.