2013-10-17 33 views
0

我刚刚对方向有个基本问题。目前我的应用只支持纵向模式的手机。我只是改变它支持平板电脑,但我想知道如何使它适用于平板电脑的两个方向,保持手机的方向为肖像。这里是我的清单中的代码,将其设置为纵向的一部分:为手机设置纵向,但是纵向和横向都适用于平板电脑

<activity 
      android:name=".activities.SplashActivity" 
      android:clearTaskOnLaunch="true" 
      android:label="@string/app_name" 
      android:launchMode="singleTop" 
      android:noHistory="true" 
      android:screenOrientation="portrait" 
      android:theme="@style/AppBaseTheme.NoActionBar" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
      <intent-filter> 
       <action android:name="android.intent.action.VIEW" /> 

       <category android:name="android.intent.category.DEFAULT" /> 
       <category android:name="android.intent.category.BROWSABLE" /> 

       <data android:scheme="https" android:path="/msf1.0/public/mobilebootstrapper.aspx"/> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name=".activities.MainActivity" 
      android:configChanges="orientation|keyboardHidden|screenSize" 
      android:launchMode="singleTask" 
      android:screenOrientation="portrait" 
      android:windowSoftInputMode="stateUnchanged|adjustResize" > 
     </activity> 

回答

4

你可以叫setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); INE您活动的onCreate方法,如果该设备是手机。要确定设备是手机还是平板电脑,您可以查看this question

+0

所以我基本上设置setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);平板电脑? –

+1

如果您希望设备根据方向传感器识别方向,则需要将其设置为ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR。所有常量在这里解释:http://developer.android.com/reference/android/R.attr.html#screenOrientation – 2Dee

+0

我如何处理在清单中定义的screenorientation作为肖像? –