在android中为不同版本编程不同的布局 [英] Program different layouts for different versions in android

查看:52
本文介绍了在android中为不同版本编程不同的布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须对我的 Android 应用程序进行编程,使其具有最佳的兼容性,以适应不同的屏幕尺寸(平板电脑和智能手机)以及版本 2.3、3.2 和 4.0.我知道可以将布局的文件夹命名为 res/layout-sw600dp/.使布局与不同的屏幕尺寸完全匹配.

I have to program my Android app with the best compatibility to different screen sizes (tablets and smartphones) and to the versions 2.3, 3.2 and 4.0. I know about the possibliy to name the folders of the layout like res/layout-sw600dp/. to match the layout exactly to different screen sizes.

因此,由于我将为平板电脑/智能手机使用完全不同的布局,我将从加载屏幕"开始,它测试使用的是哪个 Android 版本以及是否使用了平板电脑-或智能手机设备,例如在平板电脑的布局中,某些屏幕上会出现智能手机上没有的按钮.

So, cause I will use completely different layouts for Tablets / Smartphones, I would start with a "Load Screen", which tests which Android-version is used and if there is used a tablet-or smartphone-device, cause for example in the layout for the Tablet, there will be Buttons on some screens that won't be there on the smartphone.

所以我必须将所有这些放在包中,就像这样:

So I will have to separate all this in packages, like this:

  • 常见
  • 2.3
    • 平板电脑
    • 智能手机
    • 平板电脑
    • 智能手机
    • 平板电脑
    • 智能手机

    我会选择这种分离,因为在我看来,这是为即将到来的 *更新*做好准备的最佳方式,如果,假设应该添加Android 4.0 中工具栏中的按钮.

    I would choose this separation, cause it's the best way, in my opinion, to be prepared for upcoming *updates*, if, let's say there should be added a Button in the ToolBar in Android 4.0.

    在您看来,这种分离是好事还是完全过载?

    Is this separation a good thing in your opinion or is this a complete overload?

    4.0 中还有其他我应该注意的新特性吗?

    Are there any other new features in 4.0 that I should be aware of?

    推荐答案

    您还可以命名您的资源文件夹以指示版本号(如/res/layout-v11)或(/res/values-v13)

    You can also name your resource folders to indicate version number (like /res/layout-v11) or (/res/values-v13)

    关于您关于分离的问题 - 这实际上取决于您的特定要求.解决此问题的一种常见方法是回退机制:您提供一些特定的布局(例如,xlarge 横向 v11 布局),以及一些要回退的通用布局.

    Regarding your question about separation - it really depends on your particular requirement. A common approach to this problem is a fall-back mechanism: You provide a few specific layouts (for example, an xlarge landscape v11 layout), and a few generic ones to fall back to.

    当然,这是一个理想化"的解决方案;它并不总是那样工作.换句话说,仅通过提供替代资源来实际实现与这么多版本的 Android 兼容的应用程序是非常困难的.即使您使用兼容性库(这有助于减少特定于版本的代码);您仍然需要在运行时根据版本调整代码.

    Of course, this is an "idealistic" solution; and it doesn't always work that way. In other words, it is mighty difficult to practically implement an app that is compatible with so many versions of Android solely by providing alternative resources. Even if you use the compatibility libraries (which helps a bit in reducing version-specific code); you will still have to adapt your code based on the version at run-time.

    这篇关于在android中为不同版本编程不同的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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