2011-06-15 151 views
13

要锁定我的方向为纵向,我使用:

activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

我不确定哪个标志告诉活动回到依靠设备方向。我想这就是其中之一:

SCREEN_ORIENTATION_FULL_SENSOR
SCREEN_ORIENTATION_SENSOR
SCREEN_ORIENTATION_UNSPECIFIED
SCREEN_ORIENTATION_USER


锁定/解锁方向

在另一方面,为什么不是Android文档开源?该文件完全缺乏。很少的功能和标志有用的描述。

+0

关于你的额外注:我发现这直接点击,从http://developer.android.com/reference/android/app/Activity.html#setRequestedOrientation%28int%29到“定向常数用于'表示常数的含义。 – 2011-06-15 16:51:38

+0

是的,我在该页面上,并在发布此帖子之前点击了ActivityInfo.screenOrientation链接。除非再次单击“screenOrientation”,这会给出标志的实际说明,否则下一页完全无用。我不明白为什么点击“ActivityInfo.screenOrientation”页面上的一个标志没有提供解释。 – Matt 2011-06-15 17:03:28

回答

18

http://developer.android.com/reference/android/R.attr.html#screenOrientation(screenOrientation是什么这些值连接,如果你挖通了文档),SCREEN_ORIENTATION_SENSORSCREEN_ORIENTATION_FULL_SENSOR将做到这一点,取决于你想要多大的灵活性 - 不过,我怀疑你真正想要的是去回到默认设置,即SCREEN_ORIENTATION_UNSPECIFIED,以便返回到系统默认值,包括任何用户设置。

+0

谢谢。我想我没有再次点击“screenOrientation”链接,将我带到实际的属性页面。 – Matt 2011-06-15 16:54:31

+1

我认为它实际上需要我点击三到四次才能到达那里,所以我理解你的烦恼。在ACTIVITY部分中,不是应用部分中的 – 2011-06-15 16:55:45

1

一个容易解决这个为我工作是添加一行AndroidManifest.xml中,像这样:

添加机器人:screenOrientation =“肖像”>应用程序中的部分。

<application android:icon="@drawable/icon" android:label="@string/app_name"> 
    <activity android:name=".App" 
       android:label="@string/app_name" 
       android:screenOrientation="portrait"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

</application> 
+0

。 – 2012-01-24 06:47:42