XML FrameLayout lowered the OpenGL SurfaceView frame rate (fps)

I extended GLSurfaceView and implemented my own GLSurfaceView.Renderer to create my first relatively simple 2D OpenGLES Android game.

I tested my game using the following code in action on the onCreate method, which sets the surface view to be the content view, from which I got a constant 60 frames per second.

60 frames per second:

mGLView = new OpenGLTest1SurfaceView(this);


However, I have now switched to XML layout, so I can place the admob overlay in the lower right corner of the screen,

admob xml:

<Frame Layout...


admob activity:



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

  • Should I expect a lower frame rate when moving my shallow view into XML layout?
  • Is there an alternative method for serving admob ads without using XML layout?
  • Is there anything I could do to determine why my FPS apps are dropping at certain times?

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


source to share

4 answers

GLSurfaceView, which is SurfaceView, has a slightly different way of displaying in a window.

"The SurfaceView punch a hole in its window so that its surface will be displayed. The view hierarchy will take care of properly composing with any SurfaceView's surface that would normally appear on top of it. This can be used to place overlays such as buttons on top of the surface, however note that this could have an impact on performance because a full alpha blended composite will be executed every time the Surface is modified. "

First you need to paint the AdMobView in a separate window (layer) on top of the main window. Here's 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" is the layout that contains the adView. Remember, you need to set the flags for the window correctly so that your strokes will slide into the background window. You can also remove this window.

Another tip I may have is to try to disable the default background in your theme, since your GLSurfaceView sits on top of it, you don't need any additional draws.

in the subject add

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


Hope it helps.



To answer one of these points, you can create an AdMob ad and place it in your view hierarchy programmatically, you probably just need to give it a " bottom

" or something so that it stays at the bottom of the FrameLayout.

  AdView adView = new AdView(this, AdSize.BANNER, INSERT_ADMOB_ID_HERE);
  AdRequest adRequest = new AdRequest();
  // Add the adView into your view hierarchy using addView




I read about something similar a while ago, the solution was to have the overlay in a separate window, on top of gl glurfaceview.



I don't remember where, but I defiantly read some place in android that when you update the view, for example your OpenGLTest1SurfaceView, the screen invalidation is triggered on the rectangle your view takes, if you put admobe above then your fps will drop. If you place the admebel next to it, you will be fine.



All Articles