Android ScreenOrientation行为

时间:2015-02-12 14:27:57

标签: android android-layout android-manifest landscape-portrait

我有一项活动,我希望始终保持纵向布局。我在清单文件中获得了这些设置:

<activity android:name="Main"
            android:launchMode="singleInstance"
            android:label="@string/app_name" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation" android:windowSoftInputMode="stateAlwaysHidden|adjustNothing">

如果我在侧面转动设备,此设置会使活动仅将纵向布局加载到侧面。我希望布局只是保持在纵向位置,即使它意味着在将设备切换90度时查看侧面的布局。

2 个答案:

答案 0 :(得分:3)

从Android 3.2开始,您还需要将screenSize添加到configChanges

android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize"

来自handling runtime changes

的开发人员文档
  

警告:从Android 3.2(API级别13)开始,&#34; 屏幕尺寸&#34;当设备在纵向和横向之间切换时也会发生变化。

答案 1 :(得分:1)

动态强制它:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);