How to override onSetContentView when using relationship resolution policies in Andengine Base gaming activities

I am developing (learning to build :) games on andengine GLES2 . I am using basic gaming activity and the setContent view to place my ad.
Everything works fine except for permission policy.
A relationship resolution policy is one that I use with CAMERA_WIDTH = 800; and CAMERA_HEIGHT = 480; CAMERA_WIDTH = 800; and CAMERA_HEIGHT = 480; CAMERA_WIDTH = 800; and CAMERA_HEIGHT = 480;

The problem is that when overriding, the onsetContentView scene onsetContentView not centered, and the fields are displayed only at the bottom, not at the top and bottom. The same thing happens if you align it horizontally: the field will be displayed only on the right, and not on both sides. How can i fix this? I give 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 i get, you can see the white field under the scene if you select the image (it does not get attention, since the stack overflow also has a white background)

enter image description here

any suggestions would be very helpful to me

How can I solve this problem, please help me

Thanks everyone

+7
source share
1 answer

FIXED:

After playing with the layouts, I can fix it.

Now my surface view is centered and the ad is displayed in the 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); } 
+2
source

All Articles