DesignBytes: Density-independent Pixels
Why Stack Overflow recommends it
Stack Overflow users link it when explaining what dp means and how density buckets (mdpi, hdpi, xhdpi) relate to actual pixels and screen DPI.
Recommended by 2 people across 2 different months, 2013 to 2021.
What it is
A roughly ten minute Android Developers 'DesignBytes' video, presented by Roman Nurik, introducing the density-independent pixel (dp/dip). It explains how dp lets designers keep UI elements the same apparent physical size across screens of different pixel density.
What people said
Strong rec Bryan Herbst · 2013-10 · Stack Overflow · on “How it looks like : XHDPI PSD on Nexus 4 Screen?”
You should watch Roman Nurik's Design Bytes: Density-Independent Pixels [this video] video. First, stop thinking in pixels. Think of devices using density-independent pixels. The buckets that Android uses (ldpi, mdpi, etc.) are not measured in pixels; they are measured in dots-per-inch (DPI). Those buckets are actually: LDPI: 120 DPI MDPI: 160 DPI HDPI: 240 DPI XHDPI: 320 DPI The Nexus 4 has a DPI of precisely 320.
Strong rec Bryan Herbst · 2013-10 · Stack Overflow · on “Why aren't standard physical length units like mm used for touch UI layout?”
I think the W3C provides a decent explanation [LINK] of various units of measurement for screens, and where each has advantages and disadvantages. I would also very highly recommend Roman Nurik's Density Independent Pixels video [this video] . While it doesn't directly answer your question, it provides a lot of great information. Here are my arguments for DPs instead of mm: Resources This is probably the biggest one. When designers and developers create image or video assets, we don't use physical sizes. If you take a picture with your camera, you can't say that the picture is 5 inches tall. How tall the picture is depends on how you decide to print it out. Thus if I want to display an image to m
Recommends Lheonair · 2020-07 · Stack Overflow · on “TextView text size differences for Galaxy S7 and Galaxy S10e”
1dp has a different physical size in every screen, dp's take pixels into account. You can learn about it here: [this video] You should use SP instead of DP. SP's remain the same physical size between different screen sizes. If you get variations of size with the same SP in different screens it is not made on purpose. Still this is the recommended way to do it.
Cites Jesús Tomás · 2013-12 · Stack Overflow · on “Is dp based on the physical size of the screen? (dp =1/160 of an inch)”
Is this definition correct? dp Density-independent Pixels - 1/160 of an inch based on the physical size of the screen. I have found conflicting information: The official documentation [LINK] assumes scaled proportionally in equation “px = dp * (dpi / 160)”. Also here [this video] (3:02) Roman Nurik says “ scaled proportionally ” But in official documentation: px Pixels - corresponds to actual pixels on the screen. in Inches - based on the physical size of the screen. mm Millimeters - based on the physical size of the screen. pt Points - 1/72 of an inch based on the physical size of the screen. dp Density-independent Pixels - An abstract unit that is based on the physical density of the screen. Th
Cites Avoxur · 2015-02 · Stack Overflow · on “Height and width in dp looks different on different devices (Android)”
According to this video [this video] If I want create some element, which must looks the same on devices with different dpi (Phone, Tablet, TV). As shown on video (at 4:52), I must specify dimensions of this element in dp. But I got this (Redmi Note vs Redmi 1s (android 4.2.2 on both)): (I use IntelliJ Idea 14) Here is my code from activity: <LinearLayout xmlns:android=" [LINK] " xmlns:tools=" [LINK] " android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" tools:context=".MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:textSize="60sp"/> <LinearLayout androi
Cites overexchange · 2015-11 · Stack Overflow · on “How to compute device independent pixel units?”
But in this video [this video] , it says `160dpi` is baseline density. So, accordingly, `1dip` is `160dpi`, where as `2dip` is `320dpi`. So, `320dip` mean `320*160dpi`. This is, how I convert dip to dpi. Now, you say 320dip is 320px which is confusing
Cites abbas.aniefa · 2018-01 · Stack Overflow · on “Smallest width issue on Pixel and Pixel 2”
Thanks, I have handled it programatically. But like to know why its behaving diffrenetly. Formula is explained here [this video] , would like to know what has changed and why two device have different sw.
Cites angryITguy · 2018-08 · Stack Overflow · on “Putting screen densities into the correct bucket”
Bit late, but this may be useful to other readers. Screen density and the "bucket" Android uses to pick a resource from can be confusing. Google's documentation is pretty dense, and it takes alot of work to distill it down to something useful when writing code. Partly because there are several factors and they're telling you everything about screen density and dips. But the short answer is this. Basically, dpi is your defining factor, (if you rely on other factors like small/medium/large), this is not your answer. Otherwise, I found this [LINK] answer quite helpful and simple. Here is some code I have collated from various sources that I run on app startup to determine display information. T
Cites Corentin Martinot-Lagarde · 2021-07 · Stack Overflow · on “Get screen DPI in react native”
This is not exactly true, you are calculating an approximation of the dpi but not the actual dpi. pixelRatio intervienes between real pixel and independent pixel: real pixel distance (px) = pixelRatio * independente pixel distance (dp) exemple with Huawei Y9s (2019) metrics from [LINK] width in independant pixel = 360 dp width in real pixel = 1080 px density in independant pixel = 130 dip density in real pixel = 391 dpi ratio = 3 the upper formula gives us: 360dp * 3 ≈ 1080px => all good but ratio = 3 is different from : dpi / 160 = 391 /160 = 2.44 Android makes a confusion between the actual independant density and the bucket density value. ( [this video] ) But the rendering is different, if you