的设备无关像素基础 [英] basics of device-independent-pixels

查看:134
本文介绍了的设备无关像素基础的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IM throughoutly在Android困惑骤降。

im throughoutly confused by dips on Android.

我从参考的基础DP值是160明白。 因此,应该在宽度不80dp等于与屏幕50%的宽度的观点? 在我的Nexus One在DP的宽度大约是300dp的东西,因为它似乎。

I understand from the reference that the base for dp values is 160. So, shouldn't 80dp in width equals a view with a width of 50% of the screen ? On my Nexus One the width in dp is something around 300dp as it seems.

我在想什么吗?

THX预先

推荐答案

DP==密度无关的像素(这也是为什么它被称为早期探底,虽然我preFER使用 DP这些天)。

"dp" == "Density-independent Pixels" (This is also why it was earlier called "dip", though I prefer to use "dp" these days.)

你可以把它像其他单位 - 中(英寸),MM(毫米)等,它允许您提供一个基于屏幕的密度缩放尺寸

Think of it like other units -- "in" (inches), "mm" (millimeters), etc. It allows you to provide a size that is scaled based on the density of the screen.

我们定义MDPI是基本密度,所以10dp的MDPI屏幕上就会造成正好10像素。在一个华电国际的屏幕会造成15个像素,由于华电国际是1.5 * MDPI。

We define mdpi to be the base density, so "10dp" on an mdpi screen will result in exactly 10 pixels. On an hdpi screen it will result in 15 pixels, because hdpi is 1.5*mdpi.

请注意,尽管对于各种密度的常数是类似的DPI(MDPI是160,等),密度是的确切的DPI。它是调节用于屏幕dpi的,但并不试图准确地反映它的抽象缩放因子。 (你会使用中,毫米等的确切大小,但99.9%,这是你想要所以用DP坚持不算什么。)这大大简化了生活给大家,因为你并不需要处理众多Android有一个稍微不同的空间装置为它的用户界面,因为他们每一个微小的不同屏幕的DPI。此外,设备制造商可以选择他们的设备以实现期望的UI的密度 - 例如三星标签使用的密度比实际的DPI较大相当数量,导致总体较大的UI

Note that though the constants for various densities are similar to DPI (mdpi is 160, etc), density is not exactly DPI. It is an abstract scaling factor that adjusts for screen dpi, but does not try to exactly reflect it. (You would use "in", "mm", etc for exact sizes but 99.9% that is not what you want so stick with "dp".) This greatly simplifies life for everyone because you don't need to deal with many Android devices having a slightly different amount of space for its UI because they each of slight different screen DPIs. Also, device manufacturers can select the density of their device to achieve a desired UI -- for example the Samsung Tab uses a density that is a fair amount larger than the actual DPI, resulting in an overall larger UI.

这篇关于的设备无关像素基础的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆