简体   繁体   English

如何在Android中计算LDPI,MDPI,HDPI,XXHDPI,XXXHDPI的dp

[英]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所有填充,边距值转换为LDPIMDPIHDPIXXHDPIXXXHDPI

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具有paddingTop56dp那么对于ldpimdpixxhdpixxxhdpi给出什么值

please suggest me. 请建议我。

Density-independent pixel (dp) 密度无关像素(dp)

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: 当您使用设计时,您想知道一件事:

What's the baseline scale for the design? 设计的基准规模是多少?

Some quick answers: It's usually 1x, 2x or in rare cases 3x 快速解答:通常为1x,2x或在极少数情况下为3x

Android defines the following densities: Android定义了以下密度:

  • ldpi (low) ~120dpi ldpi(低)〜120dpi
  • mdpi (medium) ~160dpi mdpi(中)〜160dpi
  • hdpi (high) ~240dpi hdpi(高)〜240dpi
  • xhdpi (extra-high) ~320dpi xhdpi(超高)〜320dpi
  • xxhdpi (extra-extra-high) ~480dpi xxhdpi(超高)〜480dpi
  • xxxhdpi (extra-extra-extra-high) ~640dpi xxxhdpi(超高)〜640dpi

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.

相关问题 可绘制尺寸:LDPI,MDPI,HDPI,XHDPI,XXHDPI,XXXHDPI? - Sizes for drawable: LDPI, MDPI, HDPI, XHDPI, XXHDPI, XXXHDPI? Android Photoshop操作可导出到mdpi hdpi xhdpi xxhdpi和xxxhdpi - Android Photoshop actions to export to mdpi hdpi xhdpi xxhdpi and xxxhdpi android mdpi,hdpi,xhdpi,xxhdpi之间的关系如何计算 - android relationship between mdpi, hdpi, xhdpi, xxhdpi how to calculate 在Photoshop中以XXHDPI为基准100%时的Android导出裁剪然后如何裁剪意味着XHDPI,HDPI,MDPI,LDPI的大小 - Android Export Cropping When XXHDPI Taken as Baseline 100% In Photoshop Then How to crop means size of XHDPI, HDPI, MDPI, LDPI 379x379px图像的Android mdpi,hdpi,xhdpi,xxhdpi和xxxhdpi像素? - Android mdpi, hdpi, xhdpi, xxhdpi and xxxhdpi in pixels for 379x379px image? 在ldpi,mdpi,hdpi,xhdpi,xxhdpi中自动将sp相互转换 - Convert sp automatically to each other in ldpi, mdpi, hdpi, xhdpi, xxhdpi 如何在Android资产文件夹中保留hdpi,mdpi,ldpi和xhdpi文件? - How to keep hdpi,mdpi,ldpi and xhdpi files in the Android asset folder? 在dp中的XXHDPI和XXXHDPI维度用于android中的图像和图标 - XXHDPI and XXXHDPI dimensions in dp for images and icons in android 适用于Values文件夹的Android hdpi / mdpi / ldpi? - Android hdpi/mdpi/ldpi for Values folder? 如何在 mdpi、ldpi、hdpi、xhdpi 中调整图像大小 - How to resize image in mdpi, ldpi, hdpi, xhdpi
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM