Android force 水平(横向)布局
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2067426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android force Horizontal (landscape) layout
提问by Ben Mc
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.
我已经接近完成我的第一款 Android 游戏了,我遇到了一个非常简单的问题,我相信我会因为不知道如何解决它而感到愚蠢,但是我如何强制应用程序保持水平布局?现在,如果你转动手机(模拟器),它会翻转图形并挤压它们。我希望游戏水平开始并保持这种状态,无论用户如何转动手机。
Thank you.
谢谢你。
回答by Ally
Open the AndroidManifest.xml and add the following android:screenOrientation="landscape" e.g.
打开 AndroidManifest.xml 并添加以下 android:screenOrientation="landscape" eg
<activity android:name=".ActivtyName"
android:screenOrientation="landscape"
>
回答by EddieB
To do this at the View level, in case you want to change it dynamically or allow the user to select the orientation... use setRequestedOrientation.
要在视图级别执行此操作,如果您想动态更改它或允许用户选择方向...请使用 setRequestedOrientation。
thisView.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
thisView.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
etc...
等等...
回答by keyboardP
In the AndroidManifest file, try add android:screenOrientation="landscape"
to the activity's attribute.
在 AndroidManifest 文件中,尝试添加android:screenOrientation="landscape"
到活动的属性。
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
或者,您可以使用一个R.styleable
文件并在那里设置方向设置。更多信息
回答by Erich Douglass
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.
在清单中的 Activity 上。看起来似乎没有应用程序范围的设置,因此您可能需要分别为每个 Activity 进行设置。
回答by NoviceMe
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.
这是一种更简单的方法,可能会帮助遇到同样问题但不想处理 xml 的人。您可以转到应用程序节点选择您的活动并选择屏幕方向。为清楚起见,请参阅附图。