Locking screen for Portrait or Landscape mode

Put your problem here if it does not fit any of the other categories.

Locking screen for Portrait or Landscape mode

Postby andreleitao » Thu Mar 12, 2009 9:24 pm

Hi, I have some questions.

1.How to know easily(in code) whether the device is running the application in Portrait or Landscape mode? There is a simple method to return this?
2.If the user moves a real device (G1, for example) to see the screen in Landscape mode for any application, will the application enter in Landscape mode automatically? If yes, please read question 3 below. :)
3.How to lock the device screen for Portrait or Landscape mode only? For example, my application was designed to work in Landscape mode only, then does not matter how the user moves the device, the screen orientation will not be changed.

That's it! :D
andreleitao
Experienced Developer
Experienced Developer
 
Posts: 70
Joined: Tue Mar 10, 2009 9:56 pm
Location: Recife - Brazil

Top

Re: Locking screen for Portrait or Landscape mode

Postby sarangkulkarni17 » Fri Mar 13, 2009 6:04 am

andreleitao wrote:Hi, I have some questions.

1.How to know easily(in code) whether the device is running the application in Portrait or Landscape mode? There is a simple method to return this?
2.If the user moves a real device (G1, for example) to see the screen in Landscape mode for any application, will the application enter in Landscape mode automatically? If yes, please read question 3 below. :)
3.How to lock the device screen for Portrait or Landscape mode only? For example, my application was designed to work in Landscape mode only, then does not matter how the user moves the device, the screen orientation will not be changed.

That's it! :D


Hello andreleitao,

1. If you want your application in Landscape mode or Portrait mode then you have to write
android:screenOrientation="portrait" or android:screenOrientation="landsccape"

in your manifest file

default orientation is portrait.

I think this code will work

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
  2.  
  3. {
  4.  
  5. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4



When you open keyboard then automatically your Portrait mode converted into Landscape to avoid that you have to write
android:configChanges="keyboardHidden"

this means if your application is in landscape or portrait then it will remain as it is.
sarangkulkarni17
Developer
Developer
 
Posts: 29
Joined: Fri Feb 13, 2009 10:00 am
Location: Pune

Postby andreleitao » Fri Mar 13, 2009 2:12 pm

Thanks a lot sarang :D
andreleitao
Experienced Developer
Experienced Developer
 
Posts: 70
Joined: Tue Mar 10, 2009 9:56 pm
Location: Recife - Brazil

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 22 guests