简体   繁体   中英

How to override onSetContentView while Using Ratio Resolution policy in Andengine Base game activity

I am developing (learning to build :) a game with andengine GLES2 . I am using Base game activity , and I override the setContent view to place my admob ad.
Everything works fine except the resolution policy.
Ratio Resolution policy is the one I am using along with CAMERA_WIDTH = 800; and CAMERA_HEIGHT = 480; CAMERA_WIDTH = 800; and CAMERA_HEIGHT = 480;

The issue is that whenever overridden, the onsetContentView scene is not getting aligned to the center and margins are displayed only on the bottom and not on both: top and bottom. Same will happen when horizontally aligned: the margin will be displayed only at right side, not on both sides. How can i correct this? I am giving my code below:

@Override
protected void onSetContentView() {

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


    final LayoutParams layoutParams = new LayoutParams(
            android.view.ViewGroup.LayoutParams.MATCH_PARENT,
            android.view.ViewGroup.LayoutParams.MATCH_PARENT);

    layoutParams.gravity = Gravity.LEFT ;

    final android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams = new FrameLayout.LayoutParams(
            layoutParams);

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

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

    final FrameLayout frameLayout = new FrameLayout(this);
    final FrameLayout.LayoutParams frameLayoutLayoutParams = new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.FILL_PARENT,
            FrameLayout.LayoutParams.FILL_PARENT,Gravity.CENTER);

    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 )

在此输入图像描述

any suggestions will be very help full to me

How Can i solve this Isuue Please help me

Thanks to all,

FIXED:

After a 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

@Override
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());
    surfaceViewLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);

    relativeLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);


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

    this.setContentView(relativeLayout, relativeLayoutLayoutParams);



}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM