AdMob appears only after rotation

Hi !
I implemented AdMob in my Xamarin.Forms app (VS2017 community) following guidelines from
"AdMob In Xamarin.Forms – Display Google Ads In Your Mobile App" (posted by: Adam Pedley in Xamarin Help Community Site"
and it works fine but ads do not show initially in portrait mode, but only after the device is rotated to landscape. Once they show in landscape mode, I can rotate back to portrait and ads stay visible.
So any suggestions as to why ads do not show initially in portrait mode ?
I created test app using VS2017 cross platform xamarin.forms project and the problem seems to persist....
Any suggestions ?

Posts

  • kalkoskikalkoski FIMember ✭✭
    I have this same problem on Nokia 8 and Nexus 5X
  • Me too, the same problem....

  • AlmaJensen.9398AlmaJensen.9398 USMember ✭✭✭

    Try setting the minimumheight and minimumwidth request properties. Also I've notice that HorizontalAlignment="Center" sometimes causes sizing issues. There are fringe issues with XF that it doesn't always size things right. Using those 2 properties are some work arounds when I have issues similar to this. This could be happening because there is no admob content available when the page first appears so the size may be being set to 0. And then after add content shows up it gets correctly sized during a redraw.

    I think there is a way you may be able to for a redraw as well.

  • @AlmaJensen.9398 said:
    Try setting the minimumheight and minimumwidth request properties. Also I've notice that HorizontalAlignment="Center" sometimes causes sizing issues. There are fringe issues with XF that it doesn't always size things right. Using those 2 properties are some work arounds when I have issues similar to this. This could be happening because there is no admob content available when the page first appears so the size may be being set to 0. And then after add content shows up it gets correctly sized during a redraw.

    I think there is a way you may be able to for a redraw as well.

    Thank you, I put the admod in a row and set the height and now is working.

  • kalkoskikalkoski FIMember ✭✭

    Thanks for the i> @AlmaJensen.9398 said:

    Try setting the minimumheight and minimumwidth request properties. Also I've notice that HorizontalAlignment="Center" sometimes causes sizing issues. There are fringe issues with XF that it doesn't always size things right. Using those 2 properties are some work arounds when I have issues similar to this. This could be happening because there is no admob content available when the page first appears so the size may be being set to 0. And then after add content shows up it gets correctly sized during a redraw.

    I think there is a way you may be able to for a redraw as well.

    Thanks for the tip.

    I added these lines in my AdViewRenderer and it fixed the problem:

    int heightPixels = AdSize.SmartBanner.GetHeightInPixels(this.Context);
    adView.SetMinimumHeight(heightPixels);

  • ethanwjonesethanwjones Member ✭✭

    Thanks for the tip @AlmaJensen.9398!

  • quai7quai7 Member ✭✭

    thank you @AlmaJensen.9398 and @kalkoski :smile:

  • MarcoTronconeMarcoTroncone GBUniversity ✭✭✭

    This will solve the problem with the Ads:

    <controls:AdView>
                    <controls:AdView.HeightRequest>
                        <x:OnIdiom>
                            <x:OnIdiom.Phone>50</x:OnIdiom.Phone>
                            <x:OnIdiom.Tablet>90</x:OnIdiom.Tablet>
                        </x:OnIdiom>
                    </controls:AdView.HeightRequest>
                </controls:AdView>
    

    I've created a free Admob plugin for Android and iOS to add Banners, Interstitials and Rewarded Videos to a Xamarin.Project.
    It only requires a single line of code to show a Banner, an Interstitial or a Rewarded Video.
    Let me know what do you think.

    The nuget package link is: https://www.nuget.org/packages/MarcTron.Admob
    There is also a tutorial on my blog: https://www.xamarinexpert.it/blog/admob-made-easy/ (I'm updating it to reflect the changes in version 1.1)

  • EddyBoughioulEddyBoughioul USMember ✭✭

    @MarcoTroncone said:
    The nuget package link is: https://www.nuget.org/packages/MarcTron.Admob
    There is also a tutorial on my blog: https://www.xamarinexpert.it/blog/admob-made-easy/ (I'm updating it to reflect the changes in version 1.1)

    Hello finally I use requestHeight too, sometimes ads seems to be crop if banner is more than 50 px.

    I add this code in app.xaml for all control banner

    <?xml version="1.0" encoding="utf-8"?>
    <Application xmlns="http://xamarin.com/schemas/2014/forms"   
    xmlns:controls="clr-namespace:MarcTron.Plugin.Controls;assembly=Plugin.MtAdmob" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="FlyffLegacyTools.App">
        <Application.Resources>
            <ResourceDictionary>
                <!--Global Styles-->          
                <Style TargetType="controls:AdView">
                    <Setter Property="HeightRequest" >
                        <Setter.Value>
                            <OnIdiom Phone="50" Tablet="90"/>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ResourceDictionary>
        </Application.Resources>
    </Application>
    
  • shaunpryszlakshaunpryszlak USMember ✭✭

    I just noticed this on my S9. It was showing and then it stopped. Setting the HeightRequest is ok except if there are no adverts to show. Then you get a blank space.

  • shaunpryszlakshaunpryszlak USMember ✭✭
    edited May 31

    Another solution is to get the screen to redraw once it is loaded. None of the Invalidate() things seemed to work so I plumped for this. I have the following code in an event which I raise when I have finished refreshing the data for the screen. Or you could fire it after a couple of seconds from OnAppearing(). Not ideal but keeps the UI clean if there are no ads available.

                if (Device.RuntimePlatform==Device.Android)
                {
                    Device.BeginInvokeOnMainThread(()=> {
                        AdMob.IsVisible = false;
                        AdMob.IsVisible = true;
                    });
                }
    
Sign In or Register to comment.