如何为多种 Android 屏幕尺寸制作布局?

发布于 2024-10-06 18:54:11 字数 411 浏览 0 评论 0原文

我已经对适用于多种屏幕尺寸的构建布局进行了一些研究,并且正在寻找一些说明。

通常的做法是为三种屏幕尺寸(小、中、大)中的每一个制作一个单独的布局文件,或者您可以用更简单的方法来完成此操作吗?

我一直在大屏幕设备上测试我的项目,尽管我使用 DIP(密度独立像素)进行填充、边距等,但当我在较小的屏幕上查看它时,它仍然会弄乱内容。我应该为中型屏幕设计项目,然后允许 Android 适当缩放吗?

我不确定这是否是一个好问题,但我正在寻找针对多种屏幕尺寸进行设计的常见做法。你做什么工作?

编辑:除此之外,例如,假设我有一个位于屏幕底部上方 40dip 的按钮,我应该字面地写 40dip,还是应该使用某种像素数学,如 40 * screenWidth / blahblah 或其他以便它根据用户的屏幕尺寸进行缩放?我对 UI 的经验有限......

I've done some research on building layouts that work for multiple screen sizes and I'm looking for some clarification.

Is it common practice to just make a separate layout file for each of the three screen sizes (small, medium, large) or can you accomplish this with an easier method?

I've been testing my projects on a large screen device, and even though I use DIPs (density independent pixels) for padding, margins, etc, it still scrunches stuff up when I view it on smaller screens. Should I be designing my projects for medium-sized screens and then just allow Android to scale it appropriately?

I'm not sure if this is a good question or not, but I am looking for what the common practice is for designing for multiple screen sizes. What do you do?

Edit: In addition to this, for example, let's say I have a button that is 40dip above the bottom of the screen, should I literally write 40dip, or should I be using some sort of pixel math like 40 * screenWidth / blahblah or something so that it scales depending on the screen size the user has? I have limited experience with UIs...

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

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

发布评论

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

评论(3

吾家有女初长成 2024-10-13 18:54:11

谈到屏幕尺寸时,需要考虑两个轴:物理尺寸和密度。密度是通过提供倾斜测量值和适当的缩放资源来处理的。但密度并不总是意味着大小,反之亦然。请参阅http://developer.android.com/guide/practices/screens_support.html 有关机制的更多信息。

根据您支持的每个屏幕分辨率采用不同的布局并不常见,也不建议这样做,但为不同的尺寸类别(小、中、大)设计不同的布局是完全合理的。根据应用程序添加、删除或重新定位某些导航元素可能会使不同尺寸的屏幕受益。

在特定的尺寸类别内,您应该确保您的布局能够容忍精确屏幕分辨率的差异。正如 Falmarri 建议的那样,使用相对布局、权重和其他可用工具让您的布局优雅地伸展。

There are two axes to consider when it comes to screen size: physical size and density. Density is handled by providing measurements in dips and scaled resources as appropriate. But density does not always imply size or vice versa. See http://developer.android.com/guide/practices/screens_support.html for some further info on the mechanics.

It is not common or recommended to have different layouts based on each screen resolution you support, but it is entirely reasonable to design different layouts for different size classes (small, medium, large). Different sized screens might benefit from adding, removing, or repositioning certain navigation elements depending on the app.

Within a certain size class you should make sure that your layouts tolerate variances in exact screen resolution. As Falmarri suggested, use relative layouts, weights, and the other tools available to let your layout stretch gracefully.

夜血缘 2024-10-13 18:54:11

一般规则是在布局 xml 中使用密度独立像素 (dips) 进行尺寸定义 - 我看到您已经这样做了。这样做我就拥有了适用于所有设备的唯一布局。需要分割的是图形。为此,我使用 3 个不同的可绘制目录 - 'drawable-ldpi'、'drawable-mdpi' 和 'drawable-hdpi'。这样做是为了使图像在不同的屏幕密度上具有相同的尺寸(比方说,以毫米为单位)(假设屏幕尺寸相同 - 例如,正常),它们应该按如下方式缩放:

  • drawable-hdpi:150%
  • drawable- mdpi:100%
  • drawable-ldpi:75%

这可能是一个坏建议。但是,如果您查看Google 屏幕尺寸和密度图表< /a> 您可以决定不投入额外的精力来彻底测试大屏幕,因为市场上几乎没有这样的设备。

The general rule is to use Density Independent Pixels (dips) for size definitions in your layout xmls - I see you already do it. Doing so I just have the only layout for all range of devices. What needs to be splited is graphics. For that I use 3 different drawable directories - 'drawable-ldpi', 'drawable-mdpi' and 'drawable-hdpi'. This is done in order images to have the same size (let say, in millimeters) on various screen densities (assuming screen size is the same - Normal, for instance) they should be scaled as follows:

  • drawable-hdpi: 150%
  • drawable-mdpi: 100%
  • drawable-ldpi: 75%

Probably it is a bad advice. However, if you look at the Google chart of Screen Sizes and Densities you can decide to not invest your additional efforts to thorough testing for Large screens, since there are almost no such devices on the market.

青衫负雪 2024-10-13 18:54:11

不进行单独的布局并不是很常见的做法。只有当您的图像无法拉伸时,这才是真正推荐的方法。

在较小/较大屏幕的设备上查看时,内容总是看起来有点拉伸/压缩。这就是不同尺寸屏幕的定义。您应该只使用相对布局并让 android 控制特定的像素数。

No making separate layouts is not really common practice. Only when you have images that can't be stretched is that really the recommended way.

Stuff will always look a little stretched/compressed when viewing it on devices with smaller/larger screens. That's kind of the definition of a different size screen. You should just use relative layouts and let android control the specific pixel numbers.

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