16

I'm currently creating a side-scroller style game for my final year project for my degree.

I'm just wondering how you make the menu designed for when the phone is in horizontal orientation display, even when the phone is held in it's vertical orientation?

i.e. I want the user to know that the game has to be played with the phone in it's horizontal orientation and want the menu's to only display in the horizontal orientation.

Many thanks in advance.

KieH22
  • 161
  • 1
  • 1
  • 3

3 Answers3

22

Add the following attribute to your activity in your AndroidManifest.xml:

android:screenOrientation="landscape"

Tyler
  • 21,762
  • 11
  • 61
  • 90
  • Thanks a lot! Such a simple thing as well! I'm a beginner so just getting to grips with things! – KieH22 Nov 20 '10 at 16:56
5

Well, I didn't get your question right, but if you are defining your menu via xml

create a new folder in your res folder named

for layout changes:

layout_land

for horizontal specific menu:

 xml-land

for horizontal specific drawables:

drawable-land

and define your menu,layout and drawable changes there.

Further you can tell android framework that you want to handle rotation changes: by adding to your manifest(AndroidManifest.xml) activity child

android:configChanges="keyboardHidden|orientation"
android:screenOrientation="landscape"

Comment exactly what you want.

Cheers!

Shardul
  • 27,760
  • 6
  • 37
  • 35
  • Basically. Imagine you're holding your phone in the vertical position. I want what's displayed on the phone to STILL show as if you were holding the phone horizontally. For example, the game angry birds, it only allows horizontal orientation. The menu displayed doesn't change orientation if you turn the phone into the vertical position. – KieH22 Nov 20 '10 at 16:30
  • Yup, thats what I thought. You can follow above code instruction. It will work. – Shardul Nov 20 '10 at 16:31
1

Just complementing on other's answers

There are some different types of landscape and I think the best one is:

android:screenOrientation="userLandscape"

because it lets the user switch to landscape or reverse landscape using the device's sensor, or the user can block the swithing if he decides to.

I found that removing some basic controls of the user is quite annoying and should only be used if really necessary.

If you want to checkout other possible orientations just go here

Gabriel Amorim
  • 370
  • 2
  • 13