Page 1 of 1

Displaying admob banner at the bottom of the screen

Posted: Mon Oct 05, 2015 4:51 pm
by bio1712
Hi. I want to display an admob banner at the bottom of the screen.

Here is the code in GameActivity.java.
My banner displays at the top of the screen, instead of displaying at the bottom.

My game is in portrait mode.

Code: Select all

      adView = new AdView(mSingleton);
      adView.setAdSize(AdSize.SMART_BANNER);
      adView.setAdUnitId("ca-app-pub-XXXXXXXXXXXXXXXXX/XXXXXXXXX"); 
   
  
      RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
           RelativeLayout.LayoutParams.WRAP_CONTENT,
           RelativeLayout.LayoutParams.WRAP_CONTENT);
   
          params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);  //<--- I modified only this line, originally it was:  params.addRule(RelativeLayout.ALIGN_PARENT_TOP);

	  params.addRule(RelativeLayout.CENTER_HORIZONTAL);
      
      AdRequest adRequest = new AdRequest.Builder()
	  .addTestDevice("XXXXXXXXXXXXXXXXXXXXXXX")
	  .build();
   	  adView.loadAd(adRequest);
      mLayout.addView(adView, params);
Any help is appreciated. Thanks.

Re: Displaying admob banner at the bottom of the screen

Posted: Thu Oct 08, 2015 4:00 pm
by bio1712
I got It!

I had to change mLayout to RelativeLayout from AbsoluteLayout, then I had to change the gravity of mLayout using

Code: Select all

((RelativeLayout) mLayout).setGravity(Gravity.BOTTOM)

Re: Displaying admob banner at the bottom of the screen

Posted: Thu Oct 08, 2015 5:41 pm
by T-Bone
Just a tip: I think displaying an ad at the top is much more tolerable than at the bottom. You're much less likely to push it by mistake at the top, and it's less in focus, which is consider a good thing. In the end, it's of course up to every developer, I'm just throwing in my two cents.