我正在使用Nexus 4 KitKat 4.4进行开发,并尝试在我的游戏中添加“IMMERSIVE MODE”。我需要屏幕高度来正确设置“glViewport”。
以前我使用了
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public static int getScreenHeight() {
if (Main.m_activity == null)
return -1;
Display display = Main.m_activity.getWindowManager()
.getDefaultDisplay();
int height = -1;
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB){
//width = display.getWidth(); // deprecated
height = display.getHeight(); // deprecated
}else{
Point size = new Point();
display.getSize(size);
height = size.y;
}
return height;
}
在“沉浸模式”下,它不能返回屏幕的实际高度。
因此,我开始使用以下数值:
private static class Renderer implements GLSurfaceView.Renderer {
public void onSurfaceChanged(GL10 gl, int width, int height) {
当应用程序启动时,一切都正常。如果我按下主页按钮并返回到主屏幕,然后再返回游戏,onSurfaceChanged
会再次被调用,但是使用旧的错误值(非沉浸模式屏幕大小,更小,常规大小)。
沉浸式屏幕大小为800x1280 常规大小为800x1184
当我获取常规大小并将其设置在glViewport
中时,屏幕顶部会出现黑线。
PS 当我按音量按钮时,也会丢失IMMERSIVE MODE
。
PS2
我有以下方法实现。它无法处理屏幕/窗口调整大小。
@Override
public void onWindowFocusChanged(boolean hasFocus) {