andriod中的单位换算

px (pixels)像素 – 是像素,就是屏幕上实际的像素点单位。
dip或dp (device independent pixels)设备独立像素, 与设备屏幕有关。

dpi(dot per inch):屏幕像素密度,每英寸多少像素


换算公式:px = dip * (dpi / 160)

DisplayMetrics中的density = dpi / 160 

DisplayMetrics中的densityDpi就是dpi


The logical density of the display. This is a scaling factor for the Density Independent Pixel unit, where one DIP is one pixel on an approximately 160 dpi screen (for example a 240x320, 1.5"x2" screen), providing the baseline of the system's display. Thus on a 160dpi screen this density value will be 1; on a 120 dpi screen it would be .75; etc.

This value does not exactly follow the real screen size (as given by xdpi and ydpi, but rather is used to scale the size of the overall UI in steps based on gross changes in the display dpi. For example,a 240x320 screen will have a density of 1even if its width is 1.8", 1.3", etc. However, if the screen resolution is increased to320x480 but the screen size remained 1.5"x2" then the density would be increased (probably to 1.5).


1.标准是240*320画在1.5*2平方inch上。那么像每平方英寸有240*320/(1.5*2)=25600点,也就是一平方英尺的像素点为25600,所以dpi取为它的平方根160;如果你的dpi是120,那么它的密度就是0.75
2. 它要说明的是密度不只是与width有关,还与height有关,所以举例说,不管width是1.8还是1.3,它的密度都有可能是1;比如width是1.8,只要它的height是3/1.8的话,如果pixel为240*320的话,它的密度仍旧是1;同样如果width为1.3,只要它的height为3/1.3的话,像素点为240*320,则密度也是1.
3. 320*480/(1.5*2)得到单位平方英寸的点为51200,所以单位平方英寸是240*320画在1.5*2屏幕的2倍。但是这是平方英寸啊,算密度的时候要开平方的啊,所以应该是2开平方,是1.414吧,大致密度为1.5


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值