简体   繁体   English

Android App如何暂时旋转屏幕方向

[英]Android App How to rotation screen orientation temporarily

Is there any way to temporarily stop rotating the screen, perform a restore operation? 有什么办法可以暂时停止旋转屏幕,执行还原操作? Request can not be turned off gravity sensor, it only prohibits the rotating screen. 要求不能关闭重力感应器,它只能禁止屏幕旋转。

To disable the orientation change you need to tell Android that you want to handle it by yourself. 要禁用方向更改,您需要告知Android您要自己处理。

To do so, add the following to your activity in the mainfest.xml: 为此,请在mainfest.xml中的活动中添加以下内容:

android:configChanges="orientation"

Now override the following in the Activity: 现在,在“活动”中覆盖以下内容:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    // Checks the orientation of the screen
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
        Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
    }
}

If you don't load a new layout here you will just keep the orientation. 如果您在此处不加载新布局,则只需保持方向即可。

Further details you can find here: http://developer.android.com/guide/topics/resources/runtime-changes.html 您可以在此处找到更多详细信息: http : //developer.android.com/guide/topics/resources/runtime-changes.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM