Shrikanth Ravi
Shrikanth Ravi

Reputation: 33

Fragment not using landscape layout when orientation is changed

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>

Upvotes: 3

Views: 1486

Answers (1)

Hanzala
Hanzala

Reputation: 1983

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

It's preventing to override landscape layout

Upvotes: 4

Related Questions