Historically, programmers always designed computer interfaces in terms of pixels. For example, you mightmake 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 per inch (dpi), the user interface appears smaller and smaller. At some point, it becomes too hard to read. 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.
• mm (millimeters): 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:英寸

mm:毫米

pt:磅,1/72 英寸

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

dip:等同于dp

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

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

针对dip和px 的关系,做以下概述:

HVGA屏density=160;QVGA屏density=120;WVGA屏density=240;WQVGA屏density=120
density值表示每英寸有多少个显示点,与分辨率是两个概念。
不同density下屏幕分辨率信息,以480dip*800dip的 WVGA(density=240)为例

density=120时 屏幕实际分辨率为240px*400px (两个点对应一个分辨率)
状态栏和标题栏高各19px或者25dip
横屏是屏幕宽度400px 或者800dip,工作区域高度211px或者480dip
竖屏时屏幕宽度240px或者480dip,工作区域高度381px或者775dip

density=160时 屏幕实际分辨率为320px*533px (3个点对应两个分辨率)
状态栏和标题栏高个25px或者25dip
横屏是屏幕宽度533px 或者800dip,工作区域高度295px或者480dip
竖屏时屏幕宽度320px或者480dip,工作区域高度508px或者775dip

density=240时 屏幕实际分辨率为480px*800px (一个点对于一个分辨率)
状态栏和标题栏高个38px或者25dip
横屏是屏幕宽度800px 或者800dip,工作区域高度442px或者480dip
竖屏时屏幕宽度480px或者480dip,工作区域高度762px或者775dip

apk的资源包中,当屏幕density=240时使用hdpi 标签的资源
当屏幕density=160时,使用mdpi标签的资源
当屏幕density=120时,使用ldpi标签的资源。
不加任何标签的资源是各种分辨率情况下共用的。
布局时尽量使用单位dip,少使用px

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/hustpzb/archive/2010/11/20/6023145.aspx

更多相关文章

  1. Android(安卓)Banner 广告条
  2. android屏幕常亮
  3. Android获得屏幕分辨率的两种方法
  4. [Android实例] android多点触摸demo
  5. Android(安卓)Banner 广告条
  6. android edittext 键盘弹出屏幕自适应
  7. 如何去掉ListView底部的ListDivider
  8. Android中OnScrollListener的详解(Listview分批加载用到)
  9. android默认字体大小、高度、宽度

随机推荐

  1. Android(安卓)Server Push - MQTT
  2. Android(安卓)uiautomator实例使用
  3. 用android LinearLayout和RelativeLayout
  4. 《Effieicntt Android Threading》 Chapt
  5. Webview实现android简单的浏览器实例代码
  6. 关于Android中的消息机制和异步
  7. Android 打造任意层级树形控件 考验你的
  8. 如何将Android应用发布到Google Play(Andr
  9. android缩放大图片加载
  10. android 判断横竖屏问题的详解