简体   繁体   中英

android : Layout size changes on Orientation

I am facing a problem with me Layout. I am trying to build one xml file that operates both on landscape and portrait. On one specific Layout, on rotation (from portrait to landscpe) the Layout seems to expand itself. Although, every single object is there, I get a big gap.

This is how it is on Portrait.

在此处输入图片说明

These depict how it is after rotation (Landscape).

在此处输入图片说明

My xml file is:

<?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>

I am pretty sure that something is wrong with my xml, but I cannot figure it out.

Thanks in Advance.

PS: I have already the

android:configChanges="orientation|screenSize|keyboardHidden"

inside my manifest.

You should re implement the layout with the same name under layout-land so your file structure should be as follow :

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

i hope this will help you :)

found the solution.

Changed the:

android:layout_gravity="center" inside the second LinearLayout, with android:layout_gravity="top|center" .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM