我正在使用 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;
}
在IMMERSIVE MODE
中不返回屏幕的实际高度。
所以我开始使用来自
的值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) {
最佳答案
好文章,但还不够。 http://developer.android.com/training/system-ui/immersive.html
现在我们得到屏幕尺寸
public void onSurfaceChanged(GL10 gl, int width, int height) {
如果高度降低,我们会延迟 1 秒再次启用沉浸模式。 这行得通但很老套,我自己寻找规范的解决方案。
恐怕这只是 KitKat 中的错误。 我没有任何实现沉浸式模式的著名游戏。 (当然除了我们的应用)))
关于Android、GL、沉浸模式下的屏幕尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20555083/