Displaying admob banner at the bottom of the screen

A project to port LÖVE to Android handhelds
Locked
bio1712
Citizen
Posts: 72
Joined: Wed Aug 19, 2015 4:13 pm
Location: Italy

Displaying admob banner at the bottom of the screen

Post 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.
bio1712
Citizen
Posts: 72
Joined: Wed Aug 19, 2015 4:13 pm
Location: Italy

Re: Displaying admob banner at the bottom of the screen

Post 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)
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Displaying admob banner at the bottom of the screen

Post 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.
Locked

Who is online

Users browsing this forum: No registered users and 10 guests