Historically, programmers always designed UI in terms of pixels. For example, you might make a field 300 pixels wide, allow 5 pixels of spacing between columns, and define icons 16-by-16 pixels in size. The problem is that if you run that program on new displays with more and more dots(pixels) per inch (dpi), the UI appears smaller and smaller.

Resolution-independent measurements help solve this problem. Android supports all the following units:
• px (pixels): Dots on the screen.
• in (inches): Size as measured by a ruler.
• pt (points): 1/72 of an inch.
• dp (density-independent pixels): An abstract unit based on the density of the screen. On a display with 160 dots per inch, 1dp = 1px.
• dip: Synonym for dp, used more often in Google examples.
• sp (scale-independent pixels): Similar to dp, but also scaled by the user’s font size preference.
To make your interface scalable to any current and future type of display, I recommend you always use the sp unit for text sizes and the dip unit for everything else. You should also consider using vector graphics instead of bitmaps

px:像素点

in:英寸

pt:磅,1/72 英寸

density:表示每英寸有多少个dots(pixels)

dp:一个基于density的抽象单位,如果一个160dpi的屏幕,1dp=1px

dip:等同于dp

sp:同dp相似,但还会根据用户选定的字体大小来缩放。

建议使用sp作为文本的单位,其它用dip。

dp与px的换算:(必须知道所用屏幕的density)

px = (density / 160) * dp

说白了,dp就是选定了160 pixel per inch的density为基准,可以根据实际的density自动scale到实际使用的pixel。


HVGA屏density=160;

QVGA屏density=120;

WVGA屏density=240;

WQVGA屏density=120

当屏幕density=240时,使用hdpi 标签的资源
当屏幕density=160时,使用mdpi标签的资源
当屏幕density=120时,使用ldpi标签的资源。
不加任何标签的资源是各种分辨率情况下共用的。


更多相关文章

  1. Android学习——uses-sdk标签详解
  2. Android系统信息获取 之十二:获取屏幕分辨率及密度
  3. Andriod界面设计适配和Android Studio中的资源
  4. Android屏幕适配全攻略(最权威的官方适配指导)Android屏幕适配出现
  5. Android之应用资源的调用
  6. Android 1.6 支持更多的屏幕大小和分辨率
  7. Android屏幕计量单位详解
  8. Android 基于dpi的资源加载

随机推荐

  1. 实习杂记(27):android中关于横竖屏切换的那
  2. Android(安卓)属性动画(Property Animatio
  3. Android(安卓)-- Android(安卓)JUint 与
  4. 【Android(安卓)volley】Android库Volley
  5. Android(安卓)主流图片库Picasso Glide F
  6. Android(安卓)Q 电量使用图分析 show app
  7. 【startActivityForResult】Android(安卓
  8. [android源码下载索引贴】微信+二维码那
  9. Android中OpenMax的适配层
  10. Android中,把XML文件转换成Object对象的方