Android 中的相对布局以像素还是 dpi 为单位?

发布于 2024-12-19 21:40:11 字数 48 浏览 4 评论 0原文

我想了解 android 中相对布局的边距值是否以像素或 dpi 为单位? 谢谢。

i'm trying to understand if the margin values of the Relativelayout in android are in pixels or dpi ?
thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

九八野马 2024-12-26 21:40:11

在 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.

一世旳自豪 2024-12-26 21:40:11

您可以同时使用像素和 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.

心碎的声音 2024-12-26 21:40:11

你可以选择。输入 "5px""5dp",它会自行调整。

You can choose. Enter either "5px" or "5dp", and it will adapt itself.

那支青花 2024-12-26 21:40:11

我猜你指的是某些方法的值。它们以像素为单位,因此您最好使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文