gpt4 book ai didi

Android布局,是否支持orientation layout xml文件? -land 是否有效?

转载 作者:行者123 更新时间:2023-11-29 01:52:06 25 4
gpt4 key购买 nike

这有点令人沮丧。我试图想出一种布局认可的方式,在纵向模式下沿顶部水平重新定向按钮工具栏,在横向模式下沿右侧垂直方向重新定向按钮工具栏。例如我想要一排操作按钮根据方向让开。

首先,我不想在它的 layout-land 版本中复制所有 activity_main.xml 布局内容,所以我尝试使用该元素指向它的 toolbar.xml 布局和 layout-land 版本。

/res
/layout
/activity_main.xml
/toolbar.xml
/layout-land
/toolbar.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"/>
...

工具栏.xml:

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

layout-land/toolbar.xml:

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

不起作用。当平板电脑的方向改变时,我得到相同的按钮文本“Port!”和“Land!”按钮文字永远不会出现。例如我更改了按钮文本,以防我的 LinearLayout 属性未按预期对齐。

所以!我尝试使用所有描述主要布局 xml 文件的陆地/港口示例,并垃圾使用 .我创建了一个 activity_main.xml 的 layout-land 副本,并根据我期望它在横向中的显示方式调整了布局。 (我也删除了)

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

不起作用。我现在有一个干净的纵向和横向 activity_main.xml,当我的方向改变时不会出现明显的差异。

什么给了?有人有什么建议吗?顺便说一句,在这种情况下,我坚持使用 Android 2.3.4。提前致谢!

最佳答案

对于 list 中的 Activity ,移除方向标志,...然后您的 Activity 将销毁并在旋转时重新创建自身,为您提供正确包含的布局。

android:configChanges="keyboardHidden"

如果您保留它,则由您使用代码处理方向更改。

关于Android布局<include>,是否支持orientation layout xml文件? -land 是否有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17324110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com