【问题标题】:android : Layout size changes on Orientationandroid:方向上的布局大小更改
【发布时间】:2017-01-21 18:15:38
【问题描述】:

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

这是纵向的。

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

我的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"

在我的清单中。

【问题讨论】:

  • 嗨。请不要将您的解决方案编辑到问题的文本中。在 Stack Overflow 上,当一个问题有一个被接受的答案时,它就被认为已解决。请将您编辑的解决方案作为答案发布,并将其标记为已接受(可能有 24 小时的限制,您无法接受自己的答案,因此您必须再等待大约 10 个小时)。
  • 对不起。我的错。改了。

标签: android xml android-layout screen-rotation


【解决方案1】:

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

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

希望对你有帮助:)

【讨论】:

  • 谢谢。我敢打赌这是“良好做法”之一——(这里是新手)。我正在尝试通过每个意图使用一个 xml 来实现这一点(如果可以的话)。
【解决方案2】:

找到了解决办法。

改变了:

android:layout_gravity="center" 在第二个 LinearLayout 内,带有 android:layout_gravity="top|center".

【讨论】:

    【解决方案3】:

    尝试使用android:fillViewport="true" 并在ScrollView 中将layout_height 属性更改为match_parent

    【讨论】:

    • 谢谢。它没有用。我一直得到相同的输出。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-18
    • 2012-10-05
    • 2012-08-30
    相关资源
    最近更新 更多