0

Possible Duplicate:
Android - disable landscape mode?

I can't save position of view when orientation changes. I think it's because with orientation it also changes and I want that view stayed on the same position. For example of it was in the upper left corner of screen it stayed there and it doesn't matter what orientation of the device. I'm using some kind of Absolute layout. Because I need to manage few screens at the same time. So, i have x/y coordinate system. I think it's the main problem, but I can't solve it :(

I've attached images that you could see my problem. As you can see first screen is portrait mode and View is located in upper-left corner, but when I changed to landscape mode position of view is also changed to upper-right corner. And I need that position of view stayed always in left-upper corner.

  1. http://imgur.com/qo19E&u2K0hl
  2. http://imgur.com/qo19El&u2K0h

Sorry to bad screen. I'm still developing of an application and can't provide better screens :)

Ps: If you need some code, just say what part of code do you need.

Community
  • 1
  • 1
Anton
  • 1
  • 2

2 Answers2

0

Duplicate of Android - disable landscape mode?

You can force the activity to run in a particular orientation. Inside the AndroidManifest.xml use the attribute "android:screenOrientation"

See here for an example: http://developer.android.com/guide/topics/manifest/activity-element.html

Community
  • 1
  • 1
Ben Pearson
  • 7,532
  • 4
  • 30
  • 50
-1

It would be nice if you could provide some code or screenshots.

Anyway, when the orientation changes, your activity is destroyed and recreated. If you have a well designed xml layout file (using linearlayout, relativelayout and properties like "wrap_content", "fill_parent"...) it will reload it in the onCreate() method, so all the resizing should be done automatically.

If your views can be moved by the user or are loaded from runtime values, you can save it. Look at this post for exemple : Override Orientation Change But NOT Restart The Activity AND Pass State Data

Community
  • 1
  • 1
Zoleas
  • 4,869
  • 1
  • 21
  • 33
  • I've attached images that you could see my problem. As you can see first screen is portrait mode and View is located in upper-left corner, but when I changed to landscape mode position of view is also changed to upper-right corner. And I need that position of view stayed always in left-upper corner. 1. http://imgur.com/qo19E&u2K0hl 2. http://imgur.com/qo19El&u2K0h Sorry to bad screen. I'm still developing of an application and can't provide better screens :) Ps: If you need some code, just say what part of code do you need. – Anton Aug 18 '11 at 14:41
  • Well, i don't see anything weird. If you have your phone on landscape mode, the upper right corner of your second screenshort will be on the upper left corner of your landscape screen. I may miss something in your question ^^ – Zoleas Aug 18 '11 at 15:04
  • That's correct. But how can I manage it. Because I want that view stayed on the same position in Portrait and Landscape modes. Can it be done? – Anton Aug 18 '11 at 15:10
  • I don't understand what is not ok in the screenshots you provided. Can you draw them the way that they should look like? – Zoleas Aug 18 '11 at 15:20
  • In portrait mode is should be like on the screenshot, but in landscape mode it should be like this: http://imgur.com/5oC12 – Anton Aug 18 '11 at 17:40
  • Also, all controls are dynamic, so I can't add layout and layout-land to manage layout :( – Anton Aug 18 '11 at 17:41
  • That's quite a weird behavior, because when you look at your phone if it was like in your fake screen shot, the widget would be on bottom… If you have dynamic components, which can be moved by the user, i suggest either to force one of the orientation mode, or either to let it as it is now and let the user rearange the widgets in landscape mode if he wants. – Zoleas Aug 19 '11 at 09:07
  • Yeah. It's true, but if I fill workspace in landscape mode and than rotate, then some widgets will disappear - and that's bad :( – Anton Aug 19 '11 at 09:27