Could a layout exist only in layout-land folder?
Question
My application is forced to work only in landscape mode (EDIT: I mean, the activities has android:screenOrientation="landscape"
in the manifest). So, I have the layouts in the layout-land folder, and there is not a same named resource in the default portrait folder.
Sometimes, when I left my device alone for few minuts and I wake it up, I get a forced close, showing a "not resource found" in the setContentView
method.
I am guessing that in some conditions, android is looking for a portrait resource before noticing that it only needs the landscape layout. Is always mandatory to have a layout resource in the default portrait folder?
EDIT 2: I am not asking how to force an activity to show in portrait mode, I am asking if not having the corresponding portrait resource is a potential stability problem.
Solution
Hi please have a read
layout: it is all about general layouts
layout-port: it is all about a layout for widget that must change for portrait orientation
layout-land: it is all about alayout for widget that must change for landscape orientation
If in any case if you are in a landscape/portrait mode. Android firstly looks for the layout file in either the -portrait or -landscape directory first respectively, if it's not found then it will be back to the default layout directory to look.
There is no need to put layouts in layout-land folder if you know that you will be be using the landscape mode only. Use the default layout folder simply
what you can do is in yours case is
You can set the default orientation in your androidmanifest.xml
<activity android:name=".YoursActivity" android:screenOrientation="landscape" "/>
by means you can write and go for
<activity
android:name=".YoursActivity"
android:label="@string/app_name"
android:screenOrientation="landscapre" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
OTHER TIPS
You can set the default orietation in your manifest.xml
<activity android:name=".YourActivity" android:screenOrientation="landscape" "/>
You can also go for both programmatically as follows:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
But by default, the layouts in /res/layout
are applied to both portrait and landscape.
EDIT :
Also you should keep the same name of ressources in layout (dafault) and layout-land folder( you will keep your landscape adjusted layouts)
You don't have to put your layouts in layout-land folder if you know y'd be using the landscape mode only. Use the default layout folder and set the orientation to landscape in the manifest file for all your activities.
android:screenOrientation="landscape"
set your application to landscape only. Then you will not need different layout folders, just have one.
In your manifest file
<activity
android:name=".ExampleActivity"
android:label="@string/app_name"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Also see this theread
If you want to use only landscape mode in Your activities You need to add android:screenOrientation="landscape"
for each activity in AndroidManifest.xml file. For example:
<activity android:name="MainActivity" android:label="@string/app_name" android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
After that no matter where you store Your layouts in /layout-land
folder or simple /layout
folder