简体   繁体   中英

How does android manages different DPI

I have read documentation, extract data from other sources as well, but unable to understand this very basic thing.

In android we use DP , because its responsive and it stretches resources with respect to the screen sizes.

My question is there are different densities of different screens. Lets consider following 2 screen densities.

  1. mdpi - 160dpi
  2. hdpi -240 dpi

Let say i define width-height of an image as 20dpX20dp People say don't use px , because it varies from device to device, but dpi also varying from device to device,

I know it works fine, but i want to understand the science behind this, how does it manages, when there are different dpi's of different screen.

According to my understanding, 1dpi of screen won't be equal to 1dpi of other screen.

Kindly guide me. I have just give up on this.

There are two things to consider when considering the "size" of something on a digital screen: the size of the object in pixels and the physical size of the object.

When you specify the size of an object in pixels , it will have a different physical size on screens with different densities.

Take for example two devices with 5" screens. Device A has a 1920 x 1080 pixel display, while Device B has a 960 x 540 pixel display. Both are the same physical size, but have wildly different numbers of pixels on the screen. If you have an image that is 50 pixels wide by 50 pixels tall, that image will appear to be much smaller on Device A because the pixels on Device A are packed together much more closely.

DPs are a unit that allows us to specify a consistent size for objects across these varying devices. If you specify that an object should be 160dp wide, it will be about an inch wide on every device. On an mdpi device, that will be 160 pixels, but on an xhdpi device that will be 320 pixels.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM