android - Conversion of dp to px and px to dp. Conceptual misunderstanding.
问题描述
I am a bit confused regarding the conversion of dp to px and px to dp. The formula goes this way
px = dp*(dpi/160)
Let's consider two screens A & B of densities of 160 dpi and 320 dpi respectively. This itself means that in the same area B has more number of pixels than A which means the pixel size of 160dpi screen should be larger for the same screen size and should be equal to the physical size of 2 pixels of 320dpi screen. But, putting in the formula for B this gives that 1 pixel for B is equivalent to the physical size of 2 density independent pixels or 2 pixels of 160dpi screen. What am I missing here?
解决方案
尝试通过此示例了解缩放系统。假设您有一个要在每个屏幕上显示48dp x 48dp大的位图(与密度无关)。我们有:
- mDPI,160dpi 屏幕(比率1x)--> 位图:48x48 px(旧设备)
- hDPI,240dpi 屏幕(比例1.5x)--> 位图:72x72 px (48 x 1.5)
- xhDPI,320dpi 屏幕(比率2x)--> 位图:96x96 像素(48 x 2)
- xxhDPI,480dpi 屏幕(比例3x)--> 位图:144x144 像素(48 x 3)
- xxxhDPI,640dpi 屏幕(比例4x)--> 位图:192x192 px (48 x 4)
简而言之,要回答您的问题,不同密度的像素数量不同,但dps数量相同。
推荐阅读
- php - 来自mysql数据库的android-plot条形图
- javascript - 违反以下内容安全策略指令
- api - 如何通过赛普拉斯的 API 在我的数据库中创建/删除项目?
- html - 身体元素在身体之外
- android - android以编程方式将自定义值设置为自定义文本视图
- python - 如何在没有高级模型功能的情况下使用 keras 层进行训练和预测
- c++ - 具有源和目标的无向图上的 BOOST min-cut/max-flow
- visual-studio-code - 配置 VSCode 包含路径
- java - 如何将此 curl 请求转换为 Http post 请求以在 java 中上传文件?
- php - 如何将具有数据范围的 jQuery 数据表导出为 PDF、Excel、CSV 和复制