android - 更改方向时片段不使用横向布局
问题描述
我通过单击设计预览上方的创建横向版本按钮创建了片段的横向版本。然后我对横向布局文件进行了一些更改。但是当方向改变时,片段不使用该片段的横向版本。
在清单中,我添加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"
它可以防止覆盖横向布局
推荐阅读
- sql - AWS Athena [Presto] 如何仅接收过去 7 天的数据?
- c++ - 我初始化为0的变量随机变成-1?
- javascript - 根据变量值防止点击html元素
- kubernetes - cert-manager:让我们加密拒绝 ACME 帐户
- ios - UserDefaults.standard.set() 仅在 watchOS 上不起作用
- pytorch - 为什么 timm 视觉变压器位置嵌入初始化为零?
- android - 有没有办法让 actionBar 后退按钮用 putExtra 重新发送意图?
- arrays - 使用 For each Statement 循环遍历 VBA Excel 中的多维数组 - 仅第一维
- react-native - React native reducer:如何更新数组中的对象值
- r - 行名称列并修改 R 中的日期