1
votes

Here is the definition of dp unit : (if it is correct...)

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.

So, is a width of 160dp equals to 100% of the screen width for any kind of screen ?

According to some tests I performed, it seems that it is not the case.

Am I wrong ? Is there something I don't understand ?

Thanks !

3

3 Answers

3
votes

No. 160 dp is 1 inch (or extremely close). What they're saying is if you had a 160 dpi (dot per inch) device, then 1 pixel=1dp. 160 dpi was common in the early days of Android.

0
votes

Hi dpi means density of pixels per inch so 160 dpi means 160 pixels in one inch area.

Say length of device = 4 inch and breath of device = 3 inch So the Area = 4*3 = 12 squreInches We have pixel per square inch = 160 pixels so total no of pixels in screen = 12 * 160

The pixels in breath = 12 * 160 /4 = 480 Pixels The pixels in length = 12 * 160 /3 = 640 pixels

160dp in mdpi devices means 160 pixels

so if you draw the line of 160dp, it will cover 1/3rd of screen.

because 160/480 = 1/3

So please check and give your feed back.

For more information you can go through the following link.

What is the difference between "px", "dp", "dip" and "sp" on Android?

https://www.captechconsulting.com/blogs/understanding-density-independence-in-android

0
votes

No. 1dp is 1px of a 160ppi screen. This means 160dp will be 1 inch exactly. No. Of dp in a screen can be found as:

No. Of dp = (size(in px)/pixel density)*160

no. Of pixels in 1 dp can be found as:

no. Of pixels in a dp =pixel density/160.

On 160ppi screen: 1px=160/160=1dp.

On 240ppi screen: 1px=240/160=1.5dp.

On 320ppi screen: 1px=320/160=2dp.