Android:横向模式的替代布局xml

时间:2021-05-02 20:10:32

How can I have one layout for landscape and one for portrait? I want to assume extra width and conserve vertical space when the user rotates the phone over sideways.

我怎样才能有一个布局和一幅肖像?我想假设额外的宽度和保存垂直空间时,用户旋转的手机横向。

4 个解决方案

#1


197  

By default, the layouts in /res/layout are applied to both portrait and landscape.

默认情况下,/res/layout中的布局既适用于纵向布局,也适用于横向布局。

If you have for example

举个例子

/res/layout/main.xml

you can add a new folder /res/layout-land, copy main.xml into it and make the needed adjustments.

您可以添加一个新的文件夹/res/layout-land、copy main。将xml放入其中并进行必要的调整。

Android:横向模式的替代布局xml

See also http://www.androidpeople.com/android-portrait-amp-landscape-differeent-layouts and http://www.devx.com/wireless/Article/40792/1954 for some more options.

有关更多选项,请参见http://www.androidpeople.com/android-人像-amp-landscape- difference -layout和http://www.devx.com/wireless/Article/40792/1954。

#2


59  

In the current version of Android Studio (v1.0.2) you can simply add a landscape layout by clicking on the button in the visual editor shown in the screenshot below. Select "Create Landscape Variation"

在当前版本的Android Studio (v1.0.2)中,只需单击下面屏幕截图中显示的visual editor中的按钮,就可以添加景观布局。选择“创建景观变化”

Android:横向模式的替代布局xml

#3


41  

The layouts in /res/layout are applied to both portrait and landscape, unless you specify otherwise. Let’s assume we have /res/layout/home.xml for our homepage and we want it to look differently in the 2 layout types.

在/res/layout中的布局应用于人像和风景,除非您指定了其他的。假设我们有/res/layout/home。我们主页的xml,我们希望它在两种布局类型中看起来有所不同。

  1. create folder /res/layout-land (here you will keep your landscape adjusted layouts)
  2. 创建文件夹/res/layout-land(这里您将保持景观调整布局)
  3. copy home.xml there
  4. 拷贝回家。xml有
  5. make necessary changes to it
  6. 做出必要的改变。

Source

#4


0  

You can group your specific layout under the correct folder structure as follows.

您可以将特定的布局分组到正确的文件夹结构下,如下所示。

layout-land-target_version

layout-land-target_version

ie

layout-land-19 // target KitKat

KitKat layout-land-19 / /目标

likewise you can create your layouts.

同样,您也可以创建布局。

Hope this will help you

希望这能对你有所帮助

#1


197  

By default, the layouts in /res/layout are applied to both portrait and landscape.

默认情况下,/res/layout中的布局既适用于纵向布局,也适用于横向布局。

If you have for example

举个例子

/res/layout/main.xml

you can add a new folder /res/layout-land, copy main.xml into it and make the needed adjustments.

您可以添加一个新的文件夹/res/layout-land、copy main。将xml放入其中并进行必要的调整。

Android:横向模式的替代布局xml

See also http://www.androidpeople.com/android-portrait-amp-landscape-differeent-layouts and http://www.devx.com/wireless/Article/40792/1954 for some more options.

有关更多选项,请参见http://www.androidpeople.com/android-人像-amp-landscape- difference -layout和http://www.devx.com/wireless/Article/40792/1954。

#2


59  

In the current version of Android Studio (v1.0.2) you can simply add a landscape layout by clicking on the button in the visual editor shown in the screenshot below. Select "Create Landscape Variation"

在当前版本的Android Studio (v1.0.2)中,只需单击下面屏幕截图中显示的visual editor中的按钮,就可以添加景观布局。选择“创建景观变化”

Android:横向模式的替代布局xml

#3


41  

The layouts in /res/layout are applied to both portrait and landscape, unless you specify otherwise. Let’s assume we have /res/layout/home.xml for our homepage and we want it to look differently in the 2 layout types.

在/res/layout中的布局应用于人像和风景,除非您指定了其他的。假设我们有/res/layout/home。我们主页的xml,我们希望它在两种布局类型中看起来有所不同。

  1. create folder /res/layout-land (here you will keep your landscape adjusted layouts)
  2. 创建文件夹/res/layout-land(这里您将保持景观调整布局)
  3. copy home.xml there
  4. 拷贝回家。xml有
  5. make necessary changes to it
  6. 做出必要的改变。

Source

#4


0  

You can group your specific layout under the correct folder structure as follows.

您可以将特定的布局分组到正确的文件夹结构下,如下所示。

layout-land-target_version

layout-land-target_version

ie

layout-land-19 // target KitKat

KitKat layout-land-19 / /目标

likewise you can create your layouts.

同样,您也可以创建布局。

Hope this will help you

希望这能对你有所帮助