I am trying to add an Admob banner to a custom SurfaceView (my main game screen). I can place a banner at the top or bottom of the screen, but in both cases it overlaps the game screen (and hides some essential user interface elements). How can I make the banner resize the game screen upon login so that it doesn't overlap anything?
This thread provides an xml solution: How to get the ad displayed at the bottom of the screen without overlapping , but since my view is written in java, I need a way to do this programmatically. I tried to translate it, but no banner appears when I implement the code. Below are two solutions: the first one does not show the banner, and the second one shows the banner below, but with overlapping. What parameters do I need to change to get rid of the overlap?
adView = new AdView(this, AdSize.BANNER, "a14dc6ed8aead31");
gameView = new GameView(this, gameEng, adView);
RelativeLayout rl = new RelativeLayout(this);
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
RelativeLayout.LayoutParams gameViewParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
gameViewParams.addRule(RelativeLayout.ABOVE);
rl.addView(adView, adParams);
rl.addView(gameView, gameViewParams);
setContentView(rl);
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
source
share