Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 338
KieH22 Avatar asked Nov 20 '10 16:11

KieH22


People also ask

How do I force an app to landscape?

Setting the app upWhen on the main screen, under the orientation section, you will see a number of options like 'Auto-rotate OFF', 'Auto-rotate ON', 'Forced Portrait' and 'Forced Landscape'. As the names suggest, you can use these buttons as one-tap shortcuts to toggle the orientation of your device.

How do I force an app to landscape in IOS?

On an iPhone with a Home button, swipe up from the bottom of the screen to access it. On an iPhone without a Home button, swipe down from the top-right corner of the screen instead. Here, tap on the rotation lock icon (which looks like a lock with a circular arrow) to turn it on or off.


2 Answers

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

android:screenOrientation="landscape"

like image 124
Tyler Avatar answered Sep 22 '22 03:09

Tyler


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!

like image 42
Shardul Avatar answered Sep 26 '22 03:09

Shardul