Search code examples
androidandroid-layoutandroid-studioandroid-orientation

Android : Application does not seek into layout-land when the device changes his orientation


I'd like to use the layout-land subfolder to adapt my views to the landscape mode. So, I've created a subfolder "layout-land", copy my views into it and adapt layouts. So I have this :

enter image description here

My manifest :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.mpaa.cameratest.app" >

<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.mycompany.myapp.basic"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/title_activity_basic"
        android:theme="@style/FullscreenTheme" >
    </activity>
    <activity
        android:name="com.mycompany.myapp.loginActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/title_activity_login"
        android:theme="@style/FullscreenTheme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

But when I start my app and rotate my device, it's always the portrait view which is displayed (the view at the root of layout folder). It seems that android does not seek views in layout-land. The screen rotate as well, but the view is still the same.

So, I tried to create a "layout-port" folder and remove all my views from the root layout folder, but the app crashes at compilation because R.layout.activity_basic and R.layout.activity_login are undefined.

Do I miss something??

Thank you for your help.


Solution

  • Ok, I found the solution. If I want to manage different views I had to change

    android:configChanges="orientation|keyboardHidden|screenSize"
    

    with

    android:configChanges="|keyboardHidden|screenSize"
    

    I remove "orientation" from configChanges AND use the wright layout folder structure and it works fine!