Android 中的相对布局以像素还是 dpi 为单位?
我想了解 android 中相对布局的边距值是否以像素或 dpi 为单位? 谢谢。
i'm trying to understand if the margin values of the Relativelayout in android are in pixels or dpi ?
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 xml 中,您可以指定测量单位,例如
android:layout_marginTop="13dp"
。请参阅有关测量单位的文档。在代码中,您以像素为单位指定测量单位(例如 边距),但您可以从资源中读取尺寸,您可以在其中指定 dp 或 sp 等尺寸。
In xml you specifies measuring units such as
android:layout_marginTop="13dp"
. See documentation about measuring units.In code you specifies masuring units in pixels (for example margins), but you can read dimensions from resources, where you can specify dimension in dp or sp, etc.
您可以同时使用像素和 dpi。但如果您想让您的应用程序支持多屏幕,那么您必须更喜欢 dpi。因为它会根据屏幕尺寸调整尺寸。
You can use both pixels and dpi. But if you want to make your application for multiple screen support then you have to prefer dpi. Because it will adjust the size according to screen size.
你可以选择。输入
"5px"
或"5dp"
,它会自行调整。You can choose. Enter either
"5px"
or"5dp"
, and it will adapt itself.我猜你指的是某些方法的值。它们以像素为单位,因此您最好使用 displaymetrics 将 dpi 值转换为像素
I guess you are refering to the values of certain methods. they are in pixels so you better convert the dpi values to pixels using displaymetrics