I have added a Admob banner to a scene in my app by using the example from: https://forums.xamarin.com/discussion/51779/cocossahrp-and-admob.
The ad displays at the top of the screen but I want to display it at the bottom. I couldn't find any CocosSharp examples but I did find one for cocos2d-x(last post): http://discuss.cocos2d-x.org/t/admob-bottom-placement-tutorial-v3-0/13854/11
I have tried this with my code(see below) but can't get it working. Something I have noticed though is if I change the LayoutParams from 200 to size.Y the ad banner appears in the middle of the screen instead of the top but this happens even when AlignParentBottom or Gravity.Bottom is not used.
Using a RelativeLayout with AddRule:
Android.Graphics.Point size = new Android.Graphics.Point();
prActivity.WindowManager.DefaultDisplay.GetSize(size);
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(
size.X,
200);
var bannerAd = new AdView(prActivity);
bannerAd.AdSize = AdSize.SmartBanner;
bannerAd.AdUnitId = "ca-app-pub-3940256099942544/6300978111"; // Test UnitId
bannerAd.LayoutParameters = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
var lcRequestbuilder = new AdRequest.Builder();
bannerAd.LoadAd(lcRequestbuilder.Build());
adParams.AddRule(LayoutRules.AlignParentBottom); // Rule to place ad at the bottom
prActivity.AddContentView(bannerAd, adParams);
ScheduleOnce(t =>
{
bannerAd.BringToFront();
}, 3f);
Using a LinearLayout with Gravity:
Android.Graphics.Point size = new Android.Graphics.Point();
prActivity.WindowManager.DefaultDisplay.GetSize(size);
LinearLayout.LayoutParams adParams = new LinearLayout.LayoutParams(
size.X,
200);
var bannerAd = new AdView(prActivity);
bannerAd.AdSize = AdSize.SmartBanner;
bannerAd.AdUnitId = "ca-app-pub-3940256099942544/6300978111"; // Test UnitId
bannerAd.LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
var lcRequestbuilder = new AdRequest.Builder();
bannerAd.LoadAd(lcRequestbuilder.Build());
adParams.Gravity = GravityFlags.Bottom; // Gravity Flag to place ad at the bottom
prActivity.AddContentView(bannerAd, adParams);
ScheduleOnce(t =>
{
bannerAd.BringToFront();
}, 3f);