[英]android : Layout size changes on Orientation
我的布局有問題。 我正在嘗試構建一個可在橫向和縱向上運行的 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"
在我的清單里面。
您應該在 layout-land 下重新實現具有相同名稱的布局,因此您的文件結構應如下所示:
MyProject/
res/
layout/ # default (portrait)
main.xml
layout-land/ # landscape
main.xml
我希望這能幫到您 :)
找到了解決方案。
改變了:
android:layout_gravity="center"
在第二個 LinearLayout 中,使用android:layout_gravity="top|center"
。
嘗試使用android:fillViewport="true"
並在ScrollView
中將layout_height
屬性更改為match_parent
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.