1

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 !

toto_tata
  • 14,526
  • 27
  • 108
  • 198

3 Answers3

3

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.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • Thanks for your answer. Is 160dp equal to 1 inch for any screen density ? For example, is 160dp equal to 1 inch for a 320 dpi screen ? Thanks ! – toto_tata Mar 03 '16 at 13:31
  • Yes. That's why they made dp- so you could have a constant physical size regardless on the screen resolution. – Gabe Sechan Mar 03 '16 at 13:33
0

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

Community
  • 1
  • 1
Manmohan Soni
  • 6,472
  • 2
  • 23
  • 29
0

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.

S Praveen Kumar
  • 341
  • 1
  • 13