0

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.

arnp
  • 3,178
  • 6
  • 26
  • 43
  • are you using the same name for the layout file both in landscape and portrait ?? and layout folders as layout, layout-land – Siva Kumar Oct 17 '11 at 06:37
  • ya the the names of xml files are same but the folders are different. layout and layout-land. – arnp Oct 17 '11 at 06:40
  • are you not getting the layout of landscape getting loaded when you rotate the device/emulator to landscape then ?? – Siva Kumar Oct 17 '11 at 06:48
  • Ya i am getting the layout as i designed in layout-land when i rotate to landscape. But the problem is when the orientation changes the oncreate is called. That is like running the application again. I need the same instance state when i change the orientation. – arnp Oct 17 '11 at 06:56
  • I am not getting clearly. You don't want onCreate() get called on Orientation changed, m i right? – Balaji Khadake Oct 17 '11 at 07:08
  • There are many questions/answers on preserving state across orientation change. A little searching should reveal what you are looking for. For instance: http://stackoverflow.com/questions/3915952/how-to-save-state-during-orientation-change-in-android-if-the-state-is-made-of-m – goto10 Oct 17 '11 at 07:10
  • @Balaji Yes you are right. The same layout should be maintained in screen when the orientation changes.\ – arnp Oct 17 '11 at 07:11

1 Answers1

1

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

MKJParekh
  • 34,073
  • 11
  • 87
  • 98