个人觉得,这个是为了匹配不同的分辨率弄的.
Dip與屏幕的分辨率無關,與屏幕密度的大小有關.
一般在密度相同的情況下,定義組件的單位可以用dip,這樣可以保證組件在不同分辨率下,它的那個尺寸不會有大的變化.
而對於Density
假設模擬器的屏幕尺寸相同,但是分辨率不同pixels = dips * (density / 160)
屏幕分辨率相同的情況下:
  android默认屏幕为160dpi, resolution 320*480
如果,定义一个button的长度为100px,那么显示出来的长度还是100px。
此时,定义一个button的长度为100dp,pixels = dips * (density / 160)
假设屏幕为240dpi, 那么dip就是  240/160
此时,定义一个button的长度为100dp, 那么转换成px,它的显示长度就是150px.
如果,定义一个button的长度为100px,那么显示出来的长度还是100px---
注意:但是由於密度大,單位尺寸的像素點多,則分辨率相對變大,所以顯示清晰,則button的尺寸相對變小,所以看起來雖然同是100px,但是尺寸顯得小了!

解决方案 »

  1.   

    另外,activity之间传递数据与一个全局类(比如说ApplicationContext类)来存储数据,区别在哪?
    全局类可能会持续的占用一段内存,但可以把在必要的时候把相应字段设为null
    activity 之间传递数据,还需要一个bundle,需要一些准备感觉有点麻烦
      

  2.   

    DimensionA dimension value defined in XML. A dimension is specified with a number followed by a unit of measure. For example: 10px, 2in, 5sp. The following units of measure are supported by Android:dp
        Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".
    sp
        Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and the user's preference.
    pt
        Points - 1/72 of an inch based on the physical size of the screen.
    px
        Pixels - corresponds to actual pixels on the screen. This unit of measure is not recommended because the actual representation can vary across devices; each devices may have a different number of pixels per inch and may have more or fewer total pixels available on the screen.
    mm
        Millimeters - based on the physical size of the screen.
    in
        Inches - based on the physical size of the screen. http://androidappdocs.appspot.com/guide/topics/resources/more-resources.html#Dimension
      

  3.   

    请注意下面加粗的:dp
        You should use these units when specifying view dimensions in your layout, so the UI properly scales to render at the same actual size on different screens.px
        Pixels - corresponds to actual pixels on the screen. This unit of measure is not recommended because the actual representation can vary across devices; each devices may have a different number of pixels per inch and may have more or fewer total pixels available on the screen.android使用的java的设计思路,对屏幕的渲染对象最小单位是pixel,所以这就是代码中设置的数量单位是像素。