[英]How to calculate dp for LDPI,MDPI,HDPI,XXHDPI,XXXHDPI in android
i have screen which is deisgned in XHDPI . 我有XHDPI中指定的屏幕。
I have to convert all padding ,margin value of dp
into LDPI
, MDPI
, HDPI
, XXHDPI
, XXXHDPI
我必须将
dp
所有填充,边距值转换为LDPI
, MDPI
, HDPI
, XXHDPI
, XXXHDPI
Can any one please suggest me how i will calculate dp
value for follwing screen suppose i have paddingTop
in xhdpi
is 56dp
then what value we have give for ldpi
, mdpi
, xxhdpi
and xxxhdpi
谁能建议我,我将如何计算以下屏幕的
dp
值,假设我在xhdpi
具有paddingTop
为56dp
那么对于ldpi
, mdpi
, xxhdpi
和xxxhdpi
给出什么值
please suggest me. 请建议我。
A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way.
在定义UI布局时应使用的虚拟像素单位,以密度独立的方式表示布局尺寸或位置。 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.
与密度无关的像素等效于160 dpi屏幕上的一个物理像素,这是系统为“中”密度屏幕假定的基线密度。 At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use.
在运行时,系统会根据使用中屏幕的实际密度,根据需要透明地处理dp单位的任何缩放比例。 The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160) .
dp单位到屏幕像素的转换很简单: px = dp *(dpi / 160) 。 For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels.
例如,在240 dpi屏幕上,1 dp等于1.5物理像素。 You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.
定义应用程序的UI时,应始终使用dp单位,以确保在具有不同密度的屏幕上正确显示UI。
If you want to know what's 56dp in xhdpi, that's 56dp in ldpi, mdpi, hdpi, xxhdpi, xxxhdpi as well - as the definition says, it's density-independent pixels . 如果您想知道xhdpi中的56dp,那么ldpi,mdpi,hdpi,xxhdpi,xxxhdpi中的56dp也是如此-就像定义中所说的,它是与密度无关的像素 。
When you work with a design, you want to know one thing: 当您使用设计时,您想知道一件事:
Some quick answers: It's usually 1x, 2x or in rare cases 3x 快速解答:通常为1x,2x或在极少数情况下为3x
Android defines the following densities: Android定义了以下密度:
There are some rare cases in-between, like tvdpi, but in 99% of the cases you can just simply ignore those. 中间有一些罕见的情况,例如tvdpi,但是在99%的情况下,您可以简单地忽略这些情况。
When designers say 1x, they usually refer to mdpi , 2x (or retina) refers to xhdpi and 3x design is done in xxhdpi . 当设计师说1x时,他们通常指的是mdpi ,而2x(或视网膜)指的是xhdpi,而3x设计是在xxhdpi中完成的。
Once you know the baseline, you know how to translate the pixel values from the design document to dip (density-independent pixel) . 知道基线后,您就知道如何将设计文档中的像素值转换为dip (与密度无关的像素) 。
The formula is quite simple, but if you doubt yourself, feel free to try one of the online converter tools: 公式很简单,但是如果您怀疑自己,可以随时尝试使用一种在线转换器工具:
The formula is as follows: dp = px / (dpi / 160) where dpi is the current screen density and px is the value in the base (1x) density. 公式如下: dp = px /(dpi / 160)其中dpi是当前屏幕密度,而px是基本(1x)密度值。
Or the other way around . 或者反过来 。
Also, remember to read the Best Practices from the Android Developers page! 另外,请记住阅读Android开发者页面上的最佳做法 !
If you still end up using px in your dimensions file which are not recommended, please take a look at this answer to know how to create different values folder for different screens. 如果仍然不建议在尺寸文件中使用px,请查看此答案以了解如何为不同的屏幕创建不同的value文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.