浸,PX和DPI的关系 [英] Relations between dip, px and dpi

查看:123
本文介绍了浸,PX和DPI的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果,在布局xml文件,我设定为,例如12dip大小。将始终被12像素的MDPI,因此,在华电国际部18px?

If, in a layout xml file, I set the size to be, for example 12dip. Will that always be 12px in mdpi and so 18px in hdpi?

那么,浸总是如此MDPI,并相应地扩展其它密度?

So is dip always true for mdpi and will scale accordingly for other densities?

推荐答案

这个问题是完全覆盖的官方文档。浸,PX和DPI的关系涵盖了<一href="http://developer.android.com/intl/zh-TW/guide/practices/screens_support.html#density-independence">this部分。

That question is fully covered by official documentation. Relations between dip, px and dpi are covered by this section.

报价:

密度无关像素(DP)

这是应用程序定义可以使用虚拟像素单元的   UI,到前preSS布局尺寸或   在密度无关的方式的地位。

A virtual pixel unit that applications can use in defining their UI, to express layout dimensions or position in a density-independent way.

的密度无关的象素相当于在一个物理象素   160 DPI屏幕,基线密度   由平台假定(如所述   本文档后面)。在运行时,   该平台透明地处理任何   所需要的DP单位换算,根据   在屏幕中的实际密度   使用。的DP单位转换   屏幕像素是简单的:像素= DPS   *(密度/ 160)。例如,在240 dpi的屏幕,1 DP将等于1.5   物理像素。使用DP单位   定义应用程序的用户界面是高度   建议,为确保一种方式   您在不同的用户界面的正确显示   屏幕。

The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, the baseline density assumed by the platform (as described later in this document). At run time, the platform transparently handles any scaling of the dp units needed, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: pixels = dps * (density / 160). For example, on 240 dpi screen, 1 dp would equal 1.5 physical pixels. Using dp units to define your application's UI is highly recommended, as a way of ensuring proper display of your UI on different screens.

所以语句:

在华电国际始终12px的在MDPI等18像素

that always be 12px in mdpi and so 18px in hdpi

似乎是正确的,根据文档。

seems to be correct, according to the docs.

这篇关于浸,PX和DPI的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆