简体   繁体   English

Android:设备更改方向后,应用程序不会进入布局区域

[英]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. 我想使用layout-land子文件夹使我的视图适应横向模式。 So, I've created a subfolder "layout-land", copy my views into it and adapt layouts. 因此,我创建了一个子文件夹“ layout-land”,将视图复制到其中并调整了布局。 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. 似乎android不会在布局区域中查找视图。 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. 因此,我尝试创建一个“ layout-port”文件夹,并从根布局文件夹中删除所有视图,但是由于未定义R.layout.activity_basic和R.layout.activity_login,应用程序在编译时崩溃。

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! 我从configChanges中删除了“方向”,并使用了wright布局文件夹结构,它可以正常工作!

The layout-land folder has to be a subfolder of res, not of the layout folder. layout-land文件夹必须是res的子文件夹,而不是layout文件夹。 Move the folder you have right now to res/ and your app should show the correct layout. 将您现在拥有的文件夹移动到res /,您的应用程序应显示正确的布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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