Hi
M new to android.I faced a problem i.e in landscape mode i need a layout view which doesnot have some feilds which are present in the portrait mode.I have created a layout for landscape view in such a way.In the activity i have given the conditions like if portrait display some feilds some hide.its working properly actually...first when i go from portrait to landscape it is giving what i want...but when i go to portrait mode its stopping the application.please help me.Thanks in advance
You can make two different layouts and put them in layout-port and layout-land respectively.
And make sure that you have mentioned android:configuration = "orientation" in your manifest for that activity. Try it if i have understood you correctly.
I think that the advice by Kantesh may be backwards. As explained in the docs, if you include android:configChanges="orientation" in the manifest, then the correct resource (from layout-port or layout-land) won't be automatically loaded. Instead, leave out mention of orientation from the manifest. Then, you do not need to worry about onConfigurationChanged() (don't override it). The system will automatically shut down the activity and then restart it, binding the appropriate version of configuration-dependent resources. Handling configuration changes yourself is (again, according to the docs) only a last resort to deal with performance issues that cannot be handled in other ways.
Related
Is it possible to write code on android manifest file that will automatically change screen orientation according to the device screen size?.
May this help you:
Instead of fixing the orientation on the manifest, you could use setRequestedOrientation. On the onCreate method of each activity, check if you are on a tablet or smartphone and set the desired orientation.
Another option could be Creating Multiple APKs for Different Screen Sizes, depending on your needs.
As far as I know this cannot be done in the manifest. However, you can write some code to achieve this. Have a look at the setRequestedOrientation method of Activity. Details in the documentation.
However, this will probably not generate the best user experience.
AFAIK Tablets have default orientation set to Landscape.
So this should automatically handled
Write line given below in your defined Activity in Androidmanifest.xml,
android:screenOrientation="unspecified"
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"/>
Wondering how I do build a layout with self rearranging button, when the user turns his device from portrait to landscape, using relativelayout ?
I do not want to use scrolling on my layout and I have a lot of buttons
You can provide two different main.xml (or any layout xml file) Place one in res/layout/ and one in res/layout-land/ When the device switches orientation the system will handle the "magic" of switching to the appropriate file.
Here is some documentation about supporting these type of behaviors...
If I'm understanding your question correctly what you are looking to do is have one layout displayed for portrait mode and another for landscape mode. This is actually fairly easy to accomplish.
Here is a link to a quick tutorial:
How to change your layout in Android landscape / portrait mode
I need to use my application in both landscape and portrait modes.
So i have made two layouts for both modes in two folders folder-layout and folder-layout-land.
Now when i turn the phone the layout is switching good but the same layout in landscape mode is not maintained when switching to portrait mode.
Some other different layout is getting loaded.
Is there any solution for this.
Please share.
Thanks in advance.
As you have done everything right to make 2 xml and keep int 2 folders.
i think you just need to write this with your activity declaration in Manifest
android:configChanges="orientation|keyboardHidden"
to handle to configuaration change
My problem is that I prepare my xml in portrait mode in Android but when I try to run the application with phone and get the landscape mode, my interface crash. Picture gets smaller and buttons don't appear on the screen. I want my interface to be the same whether the phone is in landscape mode or portrait mode.
How can I solve this problem? Can I prepare two different xml for one class, one for landscape and the other for portrait mode or is there any other solution?
Thanks
You have two options here. The first is to add the android:configChanges attribute to that activity in the manifest:
<activity android:name="the activity's class name" android:configChanges="orientation" >
This will stop android from recreating the activity when the orientation changes. Instead the activity's onConfigurationChanged method will be called.
The other is to make another layout that will be used when the device is in landscape. It would need to be named the same as the portrait layout and put under layout-land.
There's probably other options as well, these are just the ones that I know of.
You can easily have different layouts in different orientations, see "Screen Orientation" in Providing Resources
All you need to do is create a layout-port or layout-land directory under res, and put the alternate XML in there.