简体   繁体   中英

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 :

在此处输入图片说明

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.

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!

The layout-land folder has to be a subfolder of res, not of the layout folder. Move the folder you have right now to res/ and your app should show the correct layout.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM