开发者

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 开发者_JAVA技巧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.


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

android:screenOrientation="landscape"


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!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜