This question already has answers here:
What is the difference between px, dip, dp, and sp?
(32 answers)
Closed 4 years ago.
The first problem is the proportions in the images. Someone can tell me concordance between dip and pixel? Thanks!
You really shouldn't ask questions like this before checking for similar ones. It takes you 10 secs to google this btw.
"Density-independent pixel (dp):
A virtual pixel unit that applications can use in defining their UI, to express layout dimensions or position in a density-independent way.
The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, the baseline density assumed by the platform (as described later in this document). At run time, the platform transparently handles any scaling of the dp units needed, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: pixels = dps * (density / 160). For example, on 240 dpi screen, 1 dp would equal 1.5 physical pixels. Using dp units to define your application's UI is highly recommended, as a way of ensuring proper display of your UI on different screens."
Related
I read about dp and pixel and calculate dpi and pixel . but i am confused. I want to know if I want to create UI for my app, is better what resolution I select for beginning? I want to use of Photoshop. on design section in Android studio, there are e few devices with their resolutions,for example (480 * 800 hdpi(nexus one)) and so on . but which one is better for first create on photoshop?
I suggest using px for design
Mobile: 360 x 640
Tablet 7inch: 600 x 960
Tablet 9inch: 1024 x 768
References
https://i.stack.imgur.com/rrNoM.png
https://i.stack.imgur.com/ueFa0.png
https://i.stack.imgur.com/CAt1u.png
Use Density-independent pixel (dp) units when defining your application's UI, to ensure proper display of your UI on screens with different densities.
The android documentation says :
A virtual pixel unit that you should use when defining UI layout, to
express layout dimensions or position in a density-independent way.
The density-independent pixel is equivalent to one physical pixel on a
160 dpi screen, which is the baseline density assumed by the system
for a "medium" density screen. At runtime, the system transparently
handles any scaling of the dp units, as necessary, based on the actual
density of the screen in use. The conversion of dp units to screen
pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi
screen, 1 dp equals 1.5 physical pixels. You should always use dp
units when defining your application's UI, to ensure proper display of
your UI on screens with different densities.
You can read it here
For correct icon size you should read answer this
I am looking at setting the FontSize of my application based on how big my device is. i.e. If the device is below 8" make the font smaller than the default.
So the device I am using is a Lenovo S8-50 8-Inch Tablet and as you can see in the specifications Screen Size: 8 inches
So looking at some code on Github I see the following:
var d = Resources.System.DisplayMetrics;
this.ScreenHeight = (int)(d.HeightPixels / d.Density);
For this device the number returned is 912 and I can't figure out how this number relates to the device.
So my question is what does this number actually represent?
From the Official documentation:
Density-independent pixel (dp)
A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way.
The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.
This will also be helpful:
Understanding density independence
I am new to android. I read about DP but m still confused. In one definition it says-
dp (density-independent pixels): An abstract unit based on the density of the screen. On a display with 160 dots per inch, 1dp = 1px.
does it mean- 160 dots=1 dp = 1 px (each dot is 1 pixel , right?)
OR 1 dp = 1 dot(pixel) among the 160 dots
Pleas clarify
density-independent pixels is a virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way.
The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple:
px = dp * (dpi / 160)
For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.
For 160 dpi screen 1 dp equals 1 px.
Refer to this blog and this answer.
The android documentation say -
The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, the baseline density assumed by the platform (as described later in this document). At run time, the platform transparently handles any scaling of the dp units needed, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: pixels = dps * (density / 160). For example, on 240 dpi screen, 1 dp would equal 1.5 physical pixels. Using dp units to define your application’s UI is highly recommended, as a way of ensuring proper display of your UI on different screens.
you may take a look at the supporting multiple screens. you may also take a look at this question.
There are a lot of questions on this on here, but none that answer my specific question. When I use px, eclipse tells me to avoid it. So I did. But when I use dp, the grid/borders I am making around my cells in GridView seems too fat. I want it much thinner. When using 1 px as opposed to 1dp, I get the desired result. I understand warning on avoiding it, but should I really avoid it in this case?
Yes you should. "dp" will give pretty the same look on all devices, but pixels are not.
http://developer.android.com/guide/practices/screens_support.html
Long story short:
The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.
px doesnt work on all devices i think it stopped working in android 2.2
I recommend sticking with dp.
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
"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.
160 dots per inch. So 80dp would be 1/2 an inch, roughly.
I don't understand your question completely but I suggest you take a look at this, if you haven't already.
http://developer.android.com/guide/practices/screens_support.html
pixels = dps * (density / 160)
Density independent pixels (short: dp) are a virtual pixel unit that will be determined at the runtime of your application.
Formala:
1 dp = 1 Pixel on 160 dpi screen.
So 160 dpi is the baseline density for the system.
The conversion of dp units to screen pixels are quite simple.
Actual device pixels (px) = dp (1) * (dpi (of the device) / 160(baseline) )
For the sake of simplicity: px = dp * (dpi / 160)
Example:
If a 240 dpi device starts your app, then 1 dp equals to 1,5 actual device pixels.
Conclusion:
Dp automatically handles any scaling to bigger or smaller devices. The times where you hardcode the pixels are over. DP ensures the proper scaling on different screen densities.