![](/img/trans.png)
[英]Android: Unable to achieve screen orientation, app closes on device rotation
[英]Android App How to rotation screen orientation temporarily
有什么办法可以暂时停止旋转屏幕,执行还原操作? 要求不能关闭重力感应器,它只能禁止屏幕旋转。
要禁用方向更改,您需要告知Android您要自己处理。
为此,请在mainfest.xml中的活动中添加以下内容:
android:configChanges="orientation"
现在,在“活动”中覆盖以下内容:
@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();
}
}
如果您在此处不加载新布局,则只需保持方向即可。
您可以在此处找到更多详细信息: http : //developer.android.com/guide/topics/resources/runtime-changes.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.