开发者

Android force Horizontal (landscape) layout [duplicate]

开发者 https://www.devze.com 2022-12-16 16:22 出处:网络
This question already has answers here: Force "portrait" orientation mode (12 answers) 开发者_如何学C
This question already has answers here: Force "portrait" orientation mode (12 answers) 开发者_如何学C Closed 2 years ago.

I'm pretty close to finished with my first game for Android, and I've come across a problem that's so simple I'm sure I'll feel stupid for not knowing how to solve it, but how can I force the app to stay in a Horizontal layout? Right now, if you turn the phone (emulator) it flips the graphics and squeezes them. I want the game to start horizontally and stay that way regardless of how the user turns the phone.

Thank you.


Open the AndroidManifest.xml and add the following android:screenOrientation="landscape" e.g.

 <activity android:name=".ActivtyName" 
       android:screenOrientation="landscape"
                >


To do this at the Activity level, in case you want to change it dynamically or allow the user to select the orientation, use setRequestedOrientation in your Activity's onCreate method.

this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

etc...


In the AndroidManifest file, try add android:screenOrientation="landscape" to the activity's attribute.

e.g.

<activity android:name=".myMainActivity"
          android:screenOrientation="landscape">

Or, you could use a R.styleable file and set the Orientation settings there. More info


I think you should be able to set

android:screenOrientation="landscape"

on your Activity in the manifest. It doesn't look like there's an Application wide setting, so you'll probably need to do it for each Activity separately.


Here is an easier way might help someone having same problem and dont want to deal with xml. You can go to Application Nodes select your activity and select screen orientation. See the image attached for clarity.

Android force Horizontal (landscape) layout [duplicate]

0

精彩评论

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