Android - 如何使 UI 在不同设备上看起来相同?

发布于 2024-09-12 05:06:27 字数 101 浏览 2 评论 0原文

市场上有各种各样的设备,具有不同的屏幕尺寸、分辨率和像素密度。

通常用于确保应用程序在不同设备上看起来相同的一些布局首选项或提示/技巧是什么?

谢谢 克里斯

There is a variety of devices on the market, with different screen sizes, resolutions and pixel density.

What are some layout preferences or tips/tricks that are generally used to make sure the app looks the same across devices?

Thanks
Chris

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

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

发布评论

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

评论(3

森罗 2024-09-19 05:06:27

我总是使用“dip”作为标准统一而不是像素,
使用layout_weight来制定比例

,我的所有应用程序都完全兼容10英寸平板设备和3.2英寸屏幕的小型智能手机!

I always use the "dip" as standart unity instead of pixels,
use layout_weight to make proportions

and all my app's are fully compatible to 10 inches tablet devices and small smartphones with 3,2 inches screen!

哆啦不做梦 2024-09-19 05:06:27

首先,您可以尝试根据屏幕的百分比定位和缩放 UI 元素(例如,将按钮放置在屏幕的 75% 处)。在其他情况下,例如屏幕右侧有一个窗口,只需获取屏幕宽度减去窗口大小并将其放置在那里。

For a start, you could try positioning and scaling UI elements based of a percentage of the screen (for example, placing a button at 75% of the screen). In other circumstances, for example having a window attached to the right of the screen, just get the width of the screen minus the size of the window and place it there.

橙幽之幻 2024-09-19 05:06:27

确保您掌握布局上 wrap_contentfill_parent 之间的区别。在垂直排列的元素(如列表)中,您几乎总是希望 wrap_content 位于高度,fill_parent 位于宽度。对于水平排列的元素反之亦然。

正如 Profete162 所说,总是更喜欢 dip 单位(它可以被认为是抽象的像素大小)。它有助于确保不同的分辨率密度不会破坏硬编码的宽度和高度。理想情况下,主题代码中不应提及 dip,但理论上的好处在实践中并不总是实用的。

如今,您永远不应该使用 px 来表示某物的大小。

Make sure you grasp the different between wrap_content and fill_parent on the layouts. In in elements that are arranged vertically (like a list), you will almost always want wrap_content on the height and fill_parent on the width. Vice versa for elements arranged hortizontally.

As Profete162 said, always prefer the dip unit (it can be thought of as an abstracted pixel size). It helps insure that different resolution-densities don't break your hard-coded widths and heights. Ideally, there should never be a mention of dip in your theme code, but what is good in theory is not always pragmatic in practice.

These days, you should never use px for the size of something.

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