简体   繁体   English

在Android上处理同一类别的不同屏幕尺寸的最佳方式

[英]Best way to handle different screen sizes of the same category on Android

There are these Android screen size categories small, normal, .... 有这些Android屏幕尺寸类别小,正常,....

I thought by defining the app screens for those separately one would have covered nearly 100% of the most common screens, however, today I was proven wrong: 我认为通过单独定义应用程序屏幕可以覆盖几乎100%最常见的屏幕,但是,今天我被证明是错误的:

There is the HTC Legend with 320 x 480 (width x height) and the Samsung Galaxy with 480 x 800, both chose to be displayed with the normal definition (since I don't have large) HTC Legend有320 x 480(宽x高)和三星Galaxy有480 x 800,两者都选择显示正常的定义(因为我没有大)

What is the best way of handling this? 处理这个问题的最佳方法是什么? Do I really need to define all screens on large format too? 我是否真的需要以大格式定义所有屏幕?

Actually the width is not the problem - the same definitions work for small, normal, large - but the height really makes trouble. 实际上宽度不是问题 - 相同的定义适用于小,正常,大 - 但高度真的很麻烦。

Doou you just make the screen scollable for the height to work? 您只是让屏幕可伸缩以适应高度吗?

Thanks for any ideas! 谢谢你的任何想法!

If you want to you can further specify screen size by the minimum dimension. 如果您愿意,可以按最小尺寸进一步指定屏幕尺寸。 Here is the directory to put the layouts for screens with the smallest width of 600dp: 这是放置宽度最小为600dp的屏幕布局的目录:

layout-sw600dp

Although, I think this may only work for >=3.2 :(. However, there may be a clever way to take advantage of selector precedence. Read up. 虽然,我认为这可能仅适用于> = 3.2 :(.。但是,可能有一种巧妙的方法可以利用选择器优先级。请阅读。

I know this is a little late to recommend, but in general, try to using linear layout, weights, and 9-patch to make sure that your layout can be used for all resolutions. 我知道建议这样做有点晚了,但总的来说,请尝试使用线性布局,权重和9-patch,以确保您的布局可用于所有分辨率。 Ideally, you should only need a different layout for xlarge vs the rest. 理想情况下,你应该只需要一个不同的xlarge布局与其他布局。

One thing to do is to use 9-patch images wherever possible, Another approach would be to setup a server side mechanism that will tell the client what assets folder to use. 要做的一件事是尽可能使用9补丁图像,另一种方法是设置服务器端机制,告诉客户端要使用哪个资产文件夹。 So, on first launch after download, the client sends the server the handsets User Agent string. 因此,在下载后首次启动时,客户端会向服务器发送手机用户代理字符串。 The server determines the best assets size and sends that info back to client, which caches it. 服务器确定最佳资产大小,并将该信息发送回客户端,客户端将其缓存。 From here on the client know which folder to use. 从这里客户端知道要使用哪个文件夹。

This breaks when the app is uninstalled and installed again later. 当应用程序卸载并稍后再次安装时,这会中断。 But this too can be addressed, as in this scenario the client app will behave as initial launch after download use case. 但这也可以解决,因为在这种情况下,客户端应用程序将在下载用例之后表现为初始启动。

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

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