Android:密度无关像素和三星 Galaxy Tab
我已经通过与密度无关的像素在 Android 上完成了绝对定位,并且它在所有可用的模拟器配置文件上都运行良好。然而,三星 Galaxy Tab 的密度为 240(与 WVGA 设备类似),但分辨率要大得多:1024x600。结果,定位失效了。
是否还有其他设备的密度和分辨率似乎不匹配?我应该如何解决这些问题?这基本上意味着我不能使用与密度无关的像素,不是吗?
I've done absolute positioning on Android via density independent pixels and it works great on all the available emulator profiles. However, the Samsung Galaxy Tab has a density of 240 (like WVGA devices), but a much larger resolution: 1024x600. As a result, the positioning is off.
Are there other devices where density and resolution don't seem to fit together? How should I tackle these issues? It basically means I can't use density independent pixels, doesn't it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
密度和分辨率没有任何关系,也从来没有关系。因此,它们要么永远不会或总是“适合在一起”,具体取决于您希望如何使用该短语。
考虑到你没有真正描述任何“问题”,这是不可能回答的。
与密度无关的像素不应该与绝对定位一起使用,因为绝对定位被定义为“基于硬件像素的定位”。一般来说,应尽可能避免绝对定位。对于其预期用途(例如,通过边距相邻小部件之间的空白),与密度无关的像素就很好了。
Density and resolution have no relationship whatsoever and never have. Hence, they either never or always "fit together", depending on how you wish to use that phrase.
Considering that you did not really describe any "issues", that is impossible to answer.
Density-independent pixels are not supposed to work with absolute positioning, because absolute positioning is defined as "positioning based on hardware pixels". In general, absolute positioning is to be avoided wherever possible. Density-independent pixels, for their intended uses (e.g., whitespace between adjacent widgets via margins), are just fine.
您不应该使用绝对位置。
你应该使用RelativeLayout。
You shouldn't use absolute positions.
You should use RelativeLayout.