Android的布局<包括>中它支持方向的布局的XML文件?是否在所有-land工作? [英] Android layout <include>, does it support orientation layout xml files? Does -land work at all?

查看:170
本文介绍了Android的布局<包括>中它支持方向的布局的XML文件?是否在所有-land工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一种令人沮丧的。我试图拿出重新定向按钮工具栏沿顶部纵向水平时的布局方式批准,并沿权当垂直景观。例如我想要的操作按钮一排摆脱取决于方向的方式。

This is kind of frustrating. I was trying to come up with a layout approved way of re-orienting a toolbar of buttons along the top horizontally when in portrait, and along the right vertically when in landscape. e.g. I want a row of action buttons to get out of the way depending on the orientation.

首先,我不想重复所有的布局,土地版本它的activity_main.xml中布局的内容,所以我尝试使用元素指向一个toolbar.xml布局和布局陆版吧。

First I didn't want to duplicate all of the activity_main.xml layout content in a layout-land version of it, so I tried using the element to point to a toolbar.xml layout and layout-land version of it.

/res
  /layout
    /activity_main.xml
    /toolbar.xml
  /layout-land
    /toolbar.xml

activity_main.xml中:

activity_main.xml:

<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/rootview"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".MainActivity">
...
<include android:id="@+id/toolbar" layout="@layout/toolbar"/>
...

toolbar.xml:
    

toolbar.xml:

    <ToggleButton
      android:id="@+id/serviceToggleButton"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginRight="10dip"
      android:text="Port!" />
...

布局土地/ toolbar.xml:
    

layout-land/toolbar.xml:

    <ToggleButton
      android:id="@+id/serviceToggleButton"
      android:layout_width="64dip"
      android:layout_height="64dip"
      android:layout_marginRight="10dip"
      android:text="Land!" />
...

不工作。当平板电脑的方向改变了,我得到同样的按钮上的文字端口!,以及土地!从未出现按钮文本。例如我改变了按钮上的文字,以防万一我的LinearLayout属性并没有如我所料保持一致。

Doesn't work. When the tablet's orientation changes, I get the same button text "Port!", and the "Land!" button text never appears. e.g. I changed the button text just in case my LinearLayout attributes didn't align as I expected.

SO!我试着用所有的土地/端口的例子,描绘主要布局的XML文件,和垃圾使用下去。我创建activity_main.xml中的布局,土地副本,并调整了我如何预期它出现在景观布局。 (我删除了也一样)

SO! I tried going with all the land/port examples which depict primary layout xml files, and junk the use of . I created a layout-land copy of activity_main.xml and adjusted the layout for how I expected it to appear in landscape. (I removed the as well)

/res
  /layout
    /activity_main.xml
  /layout-land
    /activity_main.xml

不工作。我现在有一个干净的肖像和风景activity_main.xml中有明显的差异,当我的方向变化没有出现。

Doesn't work. I now have a clean portrait and landscape activity_main.xml with noticeable differences that don't appear when my orientation changes.

怎么办?任何人有什么建议?顺便说一句,在这种情况下,我坚持与Android 2.3.4。在此先感谢!

What gives? Anyone have any suggestions? BTW, in this case I'm stuck with Android 2.3.4. Thanks in advance!

推荐答案

在清单中删除这一活动的方向标志,......那么你的活动会破坏并重新创建本身的旋转给你正确包括布局。

for the activity in the manifest remove the orientation flag,...then your activity will destroy and recreate itself on rotation giving you the correctly included layout.

的android:configChanges =keyboardHidden

如果你把它留在,它是由你来处理与code的方向变化。

If you leave it in, it is up to YOU to handle the orientation change with code.

这篇关于Android的布局&LT;包括&gt;中它支持方向的布局的XML文件?是否在所有-land工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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