更改方向时不使用横向布局的片段



我通过单击设计预览上方的创建横向版本按钮创建了片段的横向版本。然后,我对横向布局文件进行了一些更改。但是当方向改变时,片段不使用该片段的横向版本。

在清单中,我向包含该片段的活动添加了android:configChanges="orientation|keyboardHidden|screenSize"

但这没有用。

纵向版本

fragment_feed_customization.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#ffffff"
tools:context="com.shrikanthravi.newslly.FeedCustomizationFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_marginTop="-45dp"
android:paddingTop="55dp"
android:clipToPadding="false"
android:layout_below="@+id/ll"
android:id="@+id/CategoryRV">
</android.support.v7.widget.RecyclerView>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:cardElevation="10dp"
app:cardCornerRadius="20dp"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp">
<Button
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Update"
android:visibility="gone"
android:textAllCaps="false"
android:textColor="@android:color/white"
android:id="@+id/UpdateButton"
android:background="@color/color2"/>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ll"
android:background="@drawable/personalize_bg_gradient"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@color/color2"
android:textSize="23sp"
android:text="Personalize your feed"
android:layout_marginTop="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="8dp"
android:layout_gravity="center"
android:gravity="center"
android:text="Pick at least 3 topics of your interest"/>
</LinearLayout>
</RelativeLayout>

横向版

fragment_feed_customization.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#ffffff"
tools:context="com.shrikanthravi.newslly.FeedCustomizationFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_marginTop="-45dp"
android:paddingTop="55dp"
android:clipToPadding="false"
android:layout_below="@+id/ll"
android:id="@+id/CategoryRV">
</android.support.v7.widget.RecyclerView>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:cardElevation="10dp"
app:cardCornerRadius="20dp"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp">
<Button
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Update"
android:visibility="gone"
android:textAllCaps="false"
android:textColor="@android:color/white"
android:id="@+id/UpdateButton"
android:background="@color/color2"/>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ll"
android:weightSum="2"
android:background="@drawable/personalize_bg_gradient"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@color/color2"
android:layout_weight="1"
android:textSize="20dp"
android:text="Personalize your feed : "
android:layout_margin="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:textSize="20dp"
android:layout_gravity="center"
android:gravity="center"
android:text="Pick at least 3 topics of your interest"/>
</LinearLayout>
</RelativeLayout>

只需删除android:configChanges="orientation|keyboardHidden|screenSize"

它阻止覆盖横向布局

最新更新