How do you create an app that only allows horizontal orientation?
Asked Answered
Q

3

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.

Qr answered 20/11, 2010 at 16:0 Comment(0)
W
22

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

android:screenOrientation="landscape"

Wilk answered 20/11, 2010 at 16:4 Comment(1)
Thanks a lot! Such a simple thing as well! I'm a beginner so just getting to grips with things!Qr
P
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!

Pooh answered 20/11, 2010 at 16:5 Comment(2)
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.Qr
Yup, thats what I thought. You can follow above code instruction. It will work.Pooh
S
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

Scurf answered 2/5, 2021 at 18:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.