您如何为多种 Android 屏幕尺寸进行布局? [英] How do you make layouts for several Android screen sizes?

查看:30
本文介绍了您如何为多种 Android 屏幕尺寸进行布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

我一直在大屏幕设备上测试我的项目,即使我使用 DIP(与密度无关的像素)来填充、边距等,当我在较小的屏幕上查看它时,它仍然会皱缩内容.我应该为中型屏幕设计我的项目,然后让 Android 对其进行适当的缩放吗?

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?

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

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

推荐答案

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

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.

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

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.

这篇关于您如何为多种 Android 屏幕尺寸进行布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆