android - XML FrameLayout 降低了我的 OpenGL SurfaceView 帧速率 (fps)

标签 android opengl-es admob

我已经扩展了 GLSurfaceView 并实现了我自己的 GLSurfaceView.Renderer 来创建我的第一个相对简单的 Android 2D OpenGLES 游戏。

我一直在将表面 View 设置为内容 View 的 Activity onCreate 方法上使用以下代码测试我的游戏,从中我获得了恒定的 60fps。

60fps Activity :

mGLView = new OpenGLTest1SurfaceView(this);
setContentView(mGLView);

但是现在我已经移动到 XML 布局,所以我可以在屏幕的右下角放置一个 admob 覆盖层,

admob xml :

<Frame Layout...
<...OpenGLTest1SurfaceView...
<com.google.ads.adView...

admob Activity :

setContentView(R.layout.main);

现在我的应用程序以看似随机的间隔在 43fps 和 60fps 之间波动。我查看了 LogCat,发现 GC 没有过度运行(每 20 秒左右一次)。

  • 将表面 View 移动到 XML 布局时,我是否应该期望较低的帧速率?
  • 是否有其他方法可以在不使用 XML 布局的情况下显示 admob 广告?
  • 我能做些什么来确定我的应用程序 FPS 在特定时间降低的原因吗?

任何帮助将不胜感激,因为我希望能够在不久的将来通过我的 OpenGL 应用程序获利。

最佳答案

作为 SurfaceView 的 GLSurfaceView 在窗口中的表示方式略有不同。

"the SurfaceView punches a hole in its window to allow its surface to be displayed. The view hierarchy will take care of correctly compositing with the Surface any siblings of the SurfaceView that would normally appear on top of it. This can be used to place overlays such as buttons on top of the Surface, though note however that it can have an impact on performance since a full alpha-blended composite will be performed each time the Surface changes."

第一步,您需要在主窗口顶部的单独窗口(图层)中绘制 AdMobView。 这是您如何操作的示例:

View topLocker = lockDownWindow.getChildAt(0);

WindowManager.LayoutParams windowParams = new WindowManager.LayoutParams();
windowParams.gravity = Gravity.TOP;
windowParams.x = 0;
windowParams.y = 0;
windowParams.height = WindowManager.LayoutParams.MATCH_PARENT;
windowParams.width = WindowManager.LayoutParams.MATCH_PARENT;
windowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
    | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
    | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
windowParams.format = PixelFormat.TRANSLUCENT;
windowParams.windowAnimations = 0;

WindowManager wm = getWindowManager();
wm.addView(yourAwesomView, windowParams);

此处的“yourAwesomeView”是一个包含 adView 的布局。请注意,您必须正确配置窗口标志,让您的触摸滑动到背景窗口。此外,您有责任删除此窗口。

我可能有的另一个建议是尝试禁用主题中的默认背景,因为您的 GLSurfaceView 位于它之上,您不希望它后面有额外的绘图。

在你的主题中添加

<item name="android:windowBackground">@null</item>

希望这对您有所帮助。

关于android - XML FrameLayout 降低了我的 OpenGL SurfaceView 帧速率 (fps),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9681436/

相关文章:

android - 使用 Gstreamer 或 ffmpeg 在 Android 上创建 rtsp 客户端

android - CPU 处理相机图像

objective-c - iOS、iSGL3D 和立方体

java - 插页式广告未展示

android - 无法使用 mopub 从 admob 获取广告

android - admob 中自定义插页式广告的图像尺寸

java - Android Studio 中的 EditText 构造函数的参数中应放入什么?

android - 在测试项目中存放测试文件

android - 在 android 媒体 Controller 上显示时间

android - 旋转后平移