如何禁用Android平板电脑的横向模式?

时间:2013-06-04 16:03:41

标签: android android-layout android-orientation

我想为手机和平板电脑禁用landsacpe模式,但是当我在下面使用此代码并在10英寸平板电脑上运行应用程序时,我会得到倒置布局。

<activity android:name="com.zookey.mathgenius.activities.LocalGameActivity"
android:screenOrientation="portrait"                 
android:configChanges="orientation|keyboardHidden|keyboard"></activity>

我如何解决这个问题?

IMAGE:

dodaj.rs/f/2G/En/2lqYaW1v/inverted.png

1 个答案:

答案 0 :(得分:0)

要以编程方式修复方向,您可以使用以下代码:

//Disables screen orientation change based on sensor
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

//Sets the screen orientation to portrait
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

//Sets the screen orientation to inverted portrait
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);

//Let system decide the orientation (when you are done)
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);