机器人 : Layout size changes on Orientation

标签 android xml android-layout screen-rotation

我的布局遇到了问题。我正在尝试构建一个可在横向和纵向上运行的 xml 文件。在一个特定的布局上,在旋转(从纵向到横向)时,布局似乎会自行扩展。虽然,每一个对象都在那里,但我得到了很大的差距。

这就是它在肖像上的样子。

enter image description here

这些描述了旋转后的情况(横向)。

enter image description here

我的 xml 文件是:

<?xml version="1.0" encoding="utf-8"?>



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimaryDark"
    android:orientation="vertical">


    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:fitsSystemWindows="false"
        android:id="@+id/coordintorLayout">



        <com.andremion.floatingnavigationview.FloatingNavigationView
            android:id="@+id/floating_navigation_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/fab_margin"
            app:layout_anchor="@+id/toolbar"
            app:layout_anchorGravity="bottom|end"
            app:drawMenuBelowFab="true"
            app:headerLayout="@layout/navigation_view_header"
            app:menu="@menu/menu" />

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimaryDark"
            android:orientation="vertical">

            <include
                layout="@layout/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <LinearLayout
                    android:id="@+id/footer"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:layout_gravity="center"
                    android:gravity="bottom|center">

                    <!--
                    <include
                        layout="@layout/single_item_customize"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"/>
                    -->
                    <ViewStub
                        android:id="@+id/layout_stub1"
                        android:inflatedId="@+id/inflated_layout_stub1"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="0.75" />

                    <ViewStub
                        android:id="@+id/layout_stub2"
                        android:inflatedId="@+id/inflated_layout_stub2"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="0.75" />
                    <ViewStub
                        android:id="@+id/layout_stub3"
                        android:inflatedId="@+id/inflated_layout_stub3"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="0.25" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="0px"
                        android:layout_weight="0.25"
                        android:inputType="textMultiLine"
                        android:ems="10"
                        android:id="@+id/editText"
                        android:background="@color/colorPrimaryDark"
                        android:clickable="false"
                        android:editable="false"
                        android:enabled="false"
                        android:focusable="false"
                        android:focusableInTouchMode="false"
                        android:freezesText="false"
                        android:linksClickable="false"
                        android:longClickable="false"
                        android:text="@string/default_message" />
                </LinearLayout >
            </ScrollView>
        </LinearLayout>

    </android.support.design.widget.CoordinatorLayout>

</LinearLayout>

我很确定我的 xml 有问题,但我无法弄清楚。

提前致谢。

PS:我已经有了

android:configChanges="orientation|screenSize|keyboardHidden"

在我的 list 中。

最佳答案

你应该在layout-land下重新实现同名布局 所以你的文件结构应该如下:

MyProject/
    res/
        layout/              # default (portrait)
            main.xml
        layout-land/         # landscape
            main.xml 

我希望这对你有帮助:)

关于机器人 : Layout size changes on Orientation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41782787/

相关文章:

java - 使用 RestAssured 根据 xsd 列表验证 xml 响应/字符串

android - 在 LinearLayout 中将 layout_weight 与 ImageView 结合使用

android - StatusBar 在键盘出现时显示

android - 如何从 firebase 在 RecyclerView 中添加搜索过滤器

android - 如何从 OnClick 事件 Android 创建一个 Observable?

c# - 如何从 XmlNodeList 中删除 XmlNode

c++ - 如何在xml中使用双引号?

android - 将主题应用于 Android 应用程序中的所有对话框

android - gradle,这是什么意思? "debug.setRoot(' 构建类型/调试')"

java - SQLiteDatabase .execSQL 期间的 Android java.lang.NullPointerException