I have a massive question to ask as I am really stuck on this and it would be create to get ads on my free application, ok first off I have been following this book
Begi
I tried it last night and got cool result, see my code in Oncreate()
of your Activity:
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setGravity(Gravity.BOTTOM|Gravity.CENTER);
// Create a banner ad
mAdView = new AdView(this);
mAdView.setAdSize(AdSize.SMART_BANNER);
mAdView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
// Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
/*For Test On Real Device*/
AdRequest adRequest= new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setId(R.id.linear);
linearLayout.setGravity(Gravity.BOTTOM | Gravity.CENTER);
LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 9f);
layoutParams1.gravity = Gravity.TOP;
view.setLayoutParams(layoutParams1);
int heightPixels = AdSize.FULL_BANNER.getHeightInPixels(this);
LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, heightPixels, 0f);
layoutParams2.gravity = Gravity.BOTTOM;
mAdView.setLayoutParams(layoutParams2);
layout.addView(view);
layout.addView(mAdView);
// Start loading the ad.
setContentView(layout);
this will show you the ads at the bottom, GL ;)