有什么办法可以暂时停止旋转屏幕,执行恢复操作?请求不能关闭重力感应,它只禁止旋转屏幕。
问问题
441 次
1 回答
0
要禁用方向更改,您需要告诉 Android 您想自己处理它。
为此,请将以下内容添加到 mainfest.xml 中的活动:
android:configChanges="orientation"
现在覆盖 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();
}
}
如果您不在这里加载新布局,您将保持方向。
您可以在此处找到更多详细信息:http: //developer.android.com/guide/topics/resources/runtime-changes.html
于 2011-12-09T11:28:14.203 回答