简体   繁体   English

如何确定一个移动应用程序中可以合理显示多少列? (屏幕尺寸/分辨率/方向)

[英]how to determine how many columns in a mobile app could be rendered reasonably? (screen size/resolution/orientation)

Question: For a mobile app being developed with a cross-platform tool, how would one determine how many columns in a mobile app could be rendered reasonably? 问题:对于使用跨平台工具开发的移动应用程序,如何确定可以合理地呈现移动应用程序中的多少列? For example how to determine whether extra columns could be placed in a layout for a given view? 例如,如何确定是否可以在给定视图的布局中放置额外的列?

Notes: 笔记:

With the mix of IOS/Android devices, different resolutions, portrait/landscape, does the answer lie in the physical dimensions of the screen? 结合使用IOS / Android设备,不同的分辨率(纵向/横向),答案是否在于屏幕的物理尺寸? I assume that using screen width in pixels might not be appropriate as it may not indicate how physically big the screen is. 我认为使用以像素为单位的屏幕宽度可能不合适,因为它可能无法指示屏幕的物理尺寸。

For example, for the sake of discussion, if you had an application that you data to be displayed in columns and you had say determined that for readability for a user that (I'm making these up): 例如,出于讨论的目的,如果您有一个应用程序,您的数据将显示在列中,并且您说过确定这一点是为了使用户易于阅读(我正在做这些):

  • iPhone Portrait - 1 column iPhone Portrait-1列
  • iPhone Landscape - 2 columns iPhone景观-2列
  • iPad Portrait - 2 columns iPad Portrait-2列
  • iPad Landscape - 3 columns iPad景观-3列

However beyond iPad/iPhone there are all the Android devices, so assuming here one needs a formula/approach to determining at run time how many columns to try to display to the user. 但是,除了iPad / iPhone之外,还有所有Android设备,因此假设这里需要一种公式/方法来确定在运行时尝试向用户显示多少列。

So the assumption is you are using a cross platform development tool such as: Corona SDK, Phone Gap, Titanium, MoSync etc 因此,假设您正在使用跨平台开发工具,例如:Corona SDK,Phone Gap,Titanium,MoSync等

You want to use density-independent pixels when considering device screen size and column sizes. 在考虑设备屏幕尺寸和列尺寸时,要使用与密度无关的像素。

I do something similar to this in one of my apps, Housters , actually. 实际上,我在自己的一个应用程序Housters中做了类似的事情。 (If you want some visualization for my answer, hit up the Google Play Store .) I'll answer in pseudo code, since you've given a spread of possible products you might use. (如果您想以某种可视化的方式来回答问题,请访问Google Play商店 。)由于您提供了可能使用的多种产品,因此我将以伪代码进行回答。

First, I determine if it's a tablet or not. 首先,我确定它是否是平板电脑。 This is rather arbitrary these days, but the following formula works well for me: 如今这相当武断,但是以下公式对我来说很有效:

var isTablet = Math.min(platformWidthInDP, platformHeightInDP) > 500;

This correctly identifies my Nexus 5, EPIC 4G, EVO 4G, Galaxy S3, and others I've tested as phones, and Nexus 7/10, Tab 7+/10, and others as tablets. 这样可以正确识别我测试过的Nexus 5,EPIC 4G,EVO 4G,Galaxy S3和其他手机,以及经过测试的Nexus 7/10,Tab 7 + / 10和其他平板电脑。

For phones, I always use 1 column, regardless of orientation. 对于电话,无论方向如何,我始终使用1列。 It was just too squashed in landscape, especially when the keyboard is up. 它只是被压扁了,特别是在键盘向上的时候。

For tablets, I calculate a relatively desirable width based on wanting the columns to fit well on the screen. 对于平板电脑,我根据希望各列能很好地适合屏幕来计算相对理想的宽度。 I take the least of the screen dimensions, divide it by two, and then make sure it's at least 320dp wide (you might be able to tolerate a smaller value, depending on your column content, such as 250dp ). 我选择了最小的屏幕尺寸,将其除以二,然后确保它的宽度至少为320dp (根据列的内容,您可能可以容许较小的值,例如250dp )。

var minPlatformWidth = Math.min(platformWidthInDP, platformHeightInDP));
var width = Math.max(minPlatformWidth / 2, 320);

This way, even with all the variations in screen sizes out there, my columns size nicely to fill the screen. 这样,即使屏幕大小有各种变化,我的列大小也可以很好地填满屏幕。 And they have a static size, so there isn't too much trickery going on when the user reorients the device. 而且它们的尺寸是静态的,因此当用户重新定位设备时,不会有太多的麻烦。

Since you are using a webview, you could abandon trying to do it via javascript, and go for the much easier (once you learn it) solution of responsive web design. 由于您使用的是Webview,因此您可以放弃尝试通过javascript进行操作,而转向响应式Web设计更简单(一旦学习)的解决方案。

See for example this: http://responsivedesign.is/develop/css/css3-multiple-columns And change the size of your browser. 例如,请参见以下内容: http : //sensitivedesign.is/develop/css/css3-multiple-columns并更改浏览器的大小。 The number of columns gets from 3 to 2, and then from 2 to 1 as you make your browser window shorter. 使浏览器窗口更短时,列数从3变为2,然后从2变为1。

Or look at this example: http://www.greenpeace.de/ Again, start making your browser window, and you will see that the design changes. 或查看以下示例: http : //www.greenpeace.de/再次,开始制作浏览器窗口,您将看到设计发生了变化。

Al that is happening with css only and it is much lighter for your application 仅在css中发生的Al,它对您的应用程序要轻得多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM