关于android多分辨率中的density和density-independent pixel的区别

来源:互联网 发布:qq农场捕鱼枪升级数据 编辑:程序博客网 时间:2024/06/05 22:44

为何要引入dip?

The reason for dip to exist is simple enough. Take for instance the T-Mobile G1. It has a pixel resolution of 320x480 pixels. Now image another device, with the same physical screen size, but more pixels, for instance 640x480. This device would have a higher pixel density than the G1.

—If you specify, in your application, a button with a width of 100 pixels, it will look at lot smaller on the 640x480 device than on the 320x480 device. Now, if you specify the width of the button to be 100 dip, the button will appear to have exactly the same size on the two devices.

如果定义一个button的宽度是100pixels,在640*480的设备中要比320*480的设备中小的多,而如果定义一个button的宽度为100dip的话,在两个设备中尺寸大小几乎相同

—The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, the baseline density assumed by the platform (as described later in this document). At run time, the platform transparently handles any scaling of the dip units needed, based on the actual density of the screen in use. The conversion of dip units to screen pixels is simple: pixels = dips * (density / 160). For example, on 240 dpi screen, 1 dip would equal 1.5 physical pixels. Using dip units to define your application's UI is highly recommended, as a way of ensuring proper display of your UI on different screens


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

原创粉丝点击