android的单位是什么意思,android各种单位都是什么意思

ec2b27efbd4ba00f60227040bea84113.png

慕后森

dp,dip,sp均为android中的概念。dp即dip(Density-independentpixel),抽象概念,在每英寸160像素(DPI=160)的屏幕上1dp=1px。Sowheredoyoubeginwhendesigningformultiplescreens?Oneapproachistoworkinthebasestandard(mediumsize,MDPI)andscaleitupordownfortheotherbuckets.Anotherapproachistostartwiththedevicewiththelargestscreensize,andthenscaledownandfigureouttheUIcompromisesyou'llneedtomakeonsmallerscreens.即一个android程序提供多套图片资源和配置文件就可以适应各种屏幕,比如一个程序定义一行四个按钮,每个按钮宽60dp,我的手机galaxynexus的4.65寸1280*720屏幕中(密度320DPI,1dp=2px),调用的每个图片都是宽120像素的,而在htc的3.8寸800*480的屏幕中(密度240DPI,1dp=1.5px)同样一行显示4个图片,每个图片宽90像素。由于长宽比例不同,实际效果会有长或宽的间隙不同的问题,估计可以在布局文件中调整,下面是官方文档中的定义。AvirtualpixelunitthatyoushouldusewhendefiningUIlayout,toexpresslayoutdimensionsorpositioninadensity-independentway.Thedensity-independentpixelisequivalenttoonephysicalpixelona160dpiscreen,whichisthebaselinedensityassumedbythesystemfora"medium"densityscreen.Atruntime,thesystemtransparentlyhandlesanyscalingofthedpunits,asnecessary,basedontheactualdensityofthescreeninuse.Theconversionofdpunitstoscreenpixelsissimple:px=dp*(dpi/160).Forexample,ona240dpiscreen,1dpequals1.5physicalpixels.Youshouldalwaysusedpunitswhendefiningyourapplication'sUI,toensureproperdisplayofyourUIonscreenswithdifferentdensities.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值