0

我不想强制屏幕处于横向或纵向模式

我希望屏幕保持其状态并防止旋转

我试图放入活动 xml

android:configChanges="keyboardHidden|orientation"

然后我添加了

android:screenOrientation="nosensor"

并且 alos 试图把它说:

android:screenOrientation="user"

然后我尝试了这段代码:

setRequestedOrientation(getRequestedOrientation());

但它仍然旋转?

4

2 回答 2

1

尝试使用

      android:screenOrientation="nosensor"

只要

如果您想强制使用该模式,请在 Manifest xml 文件中使用

           <activity android:name="ABCActivity"
             android:screenOrientation="landscape"
            android:configChanges="keyboardHidden|orientation|screenSize">
         </activity>

否则只需在你的安卓手机上关闭你的自动屏幕旋转:P

于 2013-05-23T15:18:50.463 回答
0

这是在 android 中更改语言的示例,您也可以使用此代码更改方向。从纵向和横向到其中之一(我假设您知道您当前的位置)。

Resources res = context.getResources();
    // Change locale settings in the app.
    DisplayMetrics dm = res.getDisplayMetrics();
    android.content.res.Configuration conf = res.getConfiguration();
    conf.locale = new Locale(language_code.toLowerCase());
    res.updateConfiguration(conf, dm);
于 2013-05-23T15:03:29.363 回答