Screen orientation in android - android

I have created two layout files (in res/layout and res/layout-land) for my application. But it is not displaying the proper layout file when i change the device orientation. It just displays the same layout file (res/layout) in both the modes. Why it is not picking up the landscpe mode layout file in landscape mode? Also i have added android:configChanges="keyboard|orientation" to my activity in manifest. What else i have to do? I'am a newbie to android app development.

If you are adding added android:configChanges="keyboard|orientation" in Manifest file it won't change the layout, because by adding this attribute your Activity is not re-created again so it displays the same layout as in portrait mode. So, remove android:configChanges="keyboard|orientation" from Manifest file to get it working.
If you want that your Activity should not be created again and also it should change the layout when your orientation changes you have to add code for changing the layout manually in onConfigurationChanged() check my answer here for getting it working.

You should not add this.
android:configChanges="keyboard|orientation"
in your manifest.. because it is not allowing the call for onConfigurationchanged method... which is responsible for handling the orientation changes... remove that line from you manifest and it should work...

Related

How to change layout after orientation changed without reloading app

I would like to change the layout after the screen orientation changed without reloading the app.
I added the following into AndroidManifest for not reload the app after orientation changed and it worked:
android:configChanges="orientation|screenSize"
But now, I would like to change the layout when the orientation changes WITHOUT reloading app.
For example for layout-land, I have example1.xml and for layout-port, I have example2.xml with other different code.

orientation in activitygroup with tabbar

orientation change is not working when I rotate a child activity to landscape. I added android:configChanges="orientation|keyboardHidden in all activity tags in my manifest.xml file.
I found that my app doesn't take layoyt file from layout_land folder. what is the solution for this problem.
By putting that in your manifest you are saying that you will manually handle all orientation changes. You'll have to setContentView again onConfigurationChanged OR remove it from your manifest and it will load the right layout.
Edit: found this answer afterwards which explains it

how to fix orientation issues on android

I wanted to ask about android orientation;
I made 2 different folders for layout: layout and layout-land
when the orientation changes while the application is running i don't want to restart the running activity so i fixed that problem by adding the following line of the manifest file
android:configChanges="keyboardHidden|orientation|screenSize"/>
the problem then is that the app is not switching to the appropriate layout when i rotate the phone
does someone have any idea about the best way to handle the orientation changes of an android application ( i want to keep the state of the layout when i switch )
Simple: Let Android do the hard work.
Saying configChanges="orientation" overrides the default orientation behavior especially if you're using multiple layout files.
Change this:
android:configChanges="keyboardHidden|orientation|screenSize"/>
To this
android:configChanges="keyboardHidden|screenSize"/>

Layout doesn't rotate automatically

Hi I already made two XML layout file with same name, one in layout folder and the other in layout-land.
I already add the configChanges tag in Manifest, like this:
<activity
android:name=".Main"
android:label="#string/title_activity_main"
android:configChanges="orientation|screenSize" >
...
</activity>
The layout won't change automatically after rotating my phone.
But when I started the app in Landscape orientation, it will use the layout-land xml and keep using it even after I rotated my phone into portrait. So, there is no error in the landscape code.
I'm using Android 4.1.2 for testing. Is this the problem?
Or do I need to add some code in the Activity class?
Thanks
[Update]
I tried this in freshly-made project. But the problem still the same
Remove android:configChanges="orientation".
Using this attribute means that you will handle the rotation yourself, but you want the OS to handle it for you.

Android can use wrong layout file for single-orientation activities

I discovered by accident that if you have an Activity that is set to one orientation, but contains a separate layout file for a different orientation, when the Activity is first started it will be inflated with the layout file that matches the device's physical orientation and not the layout file that matches the Activity's orientation. Thus if AndroidManifest.xml specifies
<activity
android:name=".activities.LandscapeGardener"
android:screenOrientation="sensorLandscape">
<!-- note for new readers: sensorLandscape is like landscape, but also
works upside-down.
Other activity stuff would go here. -->
</activity>
and there is a layout for LandscapeGardener in the layout-port folder, if the Activity is loaded in portrait, the portrait-specific layout will be inflated.
The reason we have this situation, by the way, is that an Activity we're developing has some portrait-specific bugs, so we decided to suppress portrait mode for users while we fix them—but of course this problem makes the suppression somewhat partial!
Note that if the device is correctly oriented at startup, it will not change to the incorrect layout.
instead of sensorLandscape, try just landscape. i'm pretty sure it works.

Categories

Resources