简体   繁体   English

为什么dp,px,mm在不同的Android手机中看起来不同

[英]Why dp, px, mm looks different in different android phones

Every time when I have to set width, height, margin, padding, etc of widget or layout i think which unit would looks same in all android phones. 每次当我必须设置小部件或布局的宽度,高度,边距,填充等时,我认为哪个单元在所有Android手机中看起来都相同。 I have tried all these units in my different apps. 我在不同的应用程序中尝试了所有这些单元。 But there are many devices where your 5dp seems 10dp or more. 但是有很多设备你的5dp似乎是10dp或更多。 I have read many articles, blogs and stackoverflow posts about screen densities that describes all phones have different screen densities thats why dp looks different in different phones. 我已经阅读了很多关于屏幕密度的文章,博客和stackoverflow帖子,这些帖子描述了所有手机都有不同的屏幕密度,这就是为什么dp在不同手机中看起来不同的原因。 But mm and cm are physical units. 但mm和cm是物理单位。 So they should be look same in different phones. 所以它们在不同的手机中应该是相同的。 But they also not working like physical units. 但他们也不像物理单位那样工作。 So my question is there any way that we can use these units or any new that look same in all mobile phones? 所以我的问题是,我们可以使用这些单位或任何在所有手机中看起来相同的新单位吗?

There are different reasons, one been the quantity of pixels within a particular screen referred as dpi (dots per inch). 有不同的原因,一个是特定屏幕内的像素数量,称为dpi(每英寸点数)。 "low" density screens have fewer pixels within a given physical area, compared to a "normal" or "high" density screen. 与“正常”或“高”密度屏幕相比,“低”密度屏幕在给定物理区域内具有更少的像素。

It also has to do whit orientation, either landscape or portrait, meaning that the screen's aspect ratio is either wide or tall. 它还必须进行横向定位,无论是横向还是纵向,这意味着屏幕的宽高比要么宽还是高。

You can get more insight on the matter here: Official documentation 您可以在此处获得有关此事的更多信息: 官方文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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