XML的FrameLayout降低了我的OpenGL SurfaceView帧率(FPS) [英] XML FrameLayout has lowered my OpenGL SurfaceView framerate (fps)

查看:124
本文介绍了XML的FrameLayout降低了我的OpenGL SurfaceView帧率(FPS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经扩展了GLSurfaceView和实施自己的GLSurfaceView.Renderer创建我的第一个比较简单的2D OpenGLES的游戏为Android。

I have extended the GLSurfaceView and implemented my own GLSurfaceView.Renderer to create my first relatively simple 2D OpenGLES game for android.

我一直在测试我的游戏使用的下列活动code onCreate方法这台表面观为内容来看,我从中获得恒定的60fps。

I have been testing my game using the following code on the activities onCreate method which sets the surface view as the content view, from which I have obtained a constant 60fps.

60fps的活动:

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

不过我现在已经转移到一个XML布局,使我可以将AdMob广告覆盖在屏幕的右下角,

However now I have moved to an XML layout so I can place an admob overlay in the bottom right corner of the screen,

AdMob的XML:

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

AdMob的活动:

setContentView(R.layout.main);

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

Now I the application fluctuates between 43fps and 60fps at seemingly random intervals. I have looked at the LogCat and the GC is not running excessively (once every 20seconds or so).

  • 我是不是应该期望一个较低的帧速率移动我的表面观为XML布局?
  • 在当前
  • 是否有显示AdMob的广告,而无需使用XML布局的另一种方法?
  • 有什么我可以做,以确定为什么我的应用程序的FPS降低了在特定的时间?

任何帮助将是很大的AP preciated,因为我希望能赚钱我的OpenGL应用程序在不久的将来。

Any help would be greatly appreciated because I would like to be able to monetize my OpenGL applications in the near future.

推荐答案

GLSurfaceView是一个SurfaceView有被psented在一个窗口中重新$ P $有点不同的方式。

GLSurfaceView being a SurfaceView has a little bit different way of being represented in a window.

的SurfaceView拳洞,它的窗口,允许其表面   被显示。该视图层次结构将正确照顾   合成与表面的SurfaceView的兄弟姐妹说   通常会出现在它的上面。这可用于放置叠加   如上表面的顶部的按钮,尽管注意到然而,它可以   因为有一个完整的alpha混合复合材料性能的影响   将每一次的表面变化进行的。

"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在一个单独的窗口(层)。 这里是你如何做到这一点的例子:

First step you need to draw AdMobView in a separate window (layer) on top of your main window. Here is an example of how you do it:

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这里是包含AD浏览报的布局。当心你必须正确地进行窗口配置标志,让您的触摸滑背景窗口。另外你resposible去除这个窗口。

"yourAwesomeView" here is a layout containing adView. Beware you have to properly configure flags for window to let your touches slip to background window. Also you're resposible for removing this window.

另外一个建议我可能是尝试禁用默认背景在你的主题,因为你GLSurfaceView是在它的上面,你不希望额外吸引它的后面。

Another advice I may have is to try disabling default background in your theme since your GLSurfaceView is on top of it, you don't want extra draws behind it.

在你的主题添加

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

希望这有助于。

Hope this helps.

这篇关于XML的FrameLayout降低了我的OpenGL SurfaceView帧率(FPS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆