Fragment not using landscape layout when orientation is changed

Shrikanth Ravi

I created a landscape version of the fragment by clicking on create landscape version button which is above the design preview. Then I made some changes in the landscape layout file. But when orientation is changed fragment is not using the landscape version of that fragment.

In the manifest, I added android:configChanges="orientation|keyboardHidden|screenSize" to the activity containing that fragment.

But that didn't work.

Portrait version

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>

Landscape version

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>

Hanzala

Just Remove android:configChanges="orientation|keyboardHidden|screenSize"

It's preventing to override landscape layout

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to save web view state in fragment on orientation changed?

How to add scrolling to the view when screen orientation is changed to landscape?

How to disable onCreate action when will orientation be changed?

Using UIImagePickerController in landscape orientation

UIWindow with wrong size when using landscape orientation

How to get landscape orientation when converting IPython notebook to PDF?

Hiding a view when orientation changes to landscape in autolayouts

Flutter landscape orientation layout

Set landscape orientation for fragment in Single Activity Architecture

How to set a variable to false when ipad orientation is changed from landscape to portrait and vice versa using javascript and react?

How to save state of searchView when orientation is changed

Landscape Orientation When Download Table HTML to PDF Using TableHTMLExport Plugin

Is there a way to use one fragment in landscape and others in portrait when using NavController?

Redraw CoreGraphics drawing when device orientation changed

Making video fullscreen automatically when the device orientation is landscape with javascript

Save recording when orientation was changed in android

Map behavior changes when changed to landscape orientation using fragments

Android: backbutton animation when orientation is changed

Orientation landscape not working properly in landscape

Display missing when layout changed to landscape

Realoding when screen orientation changed

HTML canvas breaking when keyboard is shown at landscape orientation

UIPrintInteractionController appends a blank page when the orientation is set to Landscape

Different screen orientation on different devices when landscape mode

Textview in android fragment duplicated in landscape layout

Force Landscape when orientation is locked

UIDevice orientation returns portrait when device launches as landscape

App force change orientation landscape to portrait when start purchase flow

Lock the orientation to landscape in a fragment