I am developing (Learning to build :) ) a game with andengine GLES2. I am using base game acitvity , and i overrides the setContent view to place my admob ad.
Every thing works fine except the resolution policy .
Ratio Resolution policy is the one I am using along with CAMERA_WIDTH = 800; and CAMERA_HEIGHT = 480;

The issue is whenever overided onsetContentView scene is not get aligned to center ,margins displayed only on bottom not on both top and bottom, Same will cause when horizontally align the margin will be displayed only at right side, not on both sides. how can i correct this. I am giving my code below

protected void onSetContentView() {

    System.out.println("Content setting");
    this.mRenderSurfaceView = new RenderSurfaceView(this);

    final LayoutParams layoutParams = new LayoutParams(

    layoutParams.gravity = Gravity.LEFT ;

    final android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams = new FrameLayout.LayoutParams(

    adView = new AdView(this, AdSize.BANNER, "xxxxxxxxxxxxx");

    final FrameLayout.LayoutParams adViewLayoutParams = new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.LEFT

    final FrameLayout frameLayout = new FrameLayout(this);
    final FrameLayout.LayoutParams frameLayoutLayoutParams = new FrameLayout.LayoutParams(

    frameLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
    frameLayout.addView(adView, adViewLayoutParams);

    this.setContentView(frameLayout, frameLayoutLayoutParams);
    this.mRenderSurfaceView.setRenderer(this.mEngine, this);


here is the image what i get you can see the white margin below the scene if you select the image ( its not get into attention due to stack overflow also had white background )

enter image description here

any suggestions will be very help full to me

How Can i solve this Isuue Please help me

Thanks to all,


1 Answer 1



After a little big game with the layouts I am able to fix this.

Now my surface view get aligned to center and the ad displays in a desired way.

Here is my code

protected void onSetContentView() {

    final RelativeLayout relativeLayout = new RelativeLayout(this);
    final FrameLayout.LayoutParams relativeLayoutLayoutParams = new FrameLayout.LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);

    this.mRenderSurfaceView = new RenderSurfaceView(this);
    this.mRenderSurfaceView.setRenderer(this.mEngine, this);

    final android.widget.RelativeLayout.LayoutParams surfaceViewLayoutParams = new RelativeLayout.LayoutParams(BaseGameActivity.createSurfaceViewLayoutParams());

    relativeLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);

    FrameLayout frameLayout = new FrameLayout(this);
    adView = new AdView(this, AdSize.BANNER, "xxxxxxx");

    this.setContentView(relativeLayout, relativeLayoutLayoutParams);

  • \$\begingroup\$ thanks for the code. you just saved me quite a lot of time fiddling around with the layouts;) Although my ad was supposed to be at the bottom.. now it's on the top – do you have any idea why this could be? \$\endgroup\$
    – GameDroids
    Commented Oct 1, 2013 at 23:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .