1

是否有方法检测设备的自动旋转锁定是打开还是关闭?我的应用需要访问该方法以在运行时锁定方向。获取锁定方向

回答

2

在你的清单文件在您的活动添加这个给你想为你的活动固定方向

android:screenOrientation="portrait" 

<activity android:name=".Settings" android:label="@string/app_name" android:screenOrientation="portrait"> 

或在Java代码中,你可以使用

setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
+0

没有办法通过java代码访问它吗?我希望它可以通过切换按钮进行修改 – louieansonng

+0

是的,使用setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); – Harinder

+0

我尝试通过设置锁定设备的方向,并尝试记录所请求方向的值,但无论是否切换锁定,该值都会返回-1。 – louieansonng

-3

在iPhone有一种方法

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations. 
    return YES; 
} 

要解锁方位。如果u希望把它锁住,然后改变它的值(YES(是)NO),其中u要锁定方向

+0

我很抱歉,但我工作的一个机器人应用程序。 – louieansonng