有没有办法暂时停止旋转屏幕,执行还原操作? 请求不能关闭重力传感器,它只禁止旋转屏幕。
答案 0 :(得分:0)
要禁用方向更改,您需要告诉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