locked
AdMob appears only after rotation RRS feed

  • Question

  • User373943 posted

    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 ?

    Sunday, November 25, 2018 11:40 AM

All replies

  • User302028 posted

    I have this same problem on Nokia 8 and Nexus 5X

    Monday, December 10, 2018 6:17 AM
  • User374011 posted

    Me too, the same problem....

    Tuesday, December 11, 2018 10:19 PM
  • User167259 posted

    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.

    Wednesday, December 12, 2018 2:56 AM
  • User374011 posted

    @"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.

    Wednesday, December 12, 2018 9:36 PM
  • User302028 posted

    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);

    Thursday, December 13, 2018 3:44 PM
  • User379448 posted

    Thanks for the tip @"AlmaJensen.9398"!

    Thursday, December 13, 2018 6:35 PM
  • User370239 posted

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

    Tuesday, February 19, 2019 5:24 PM
  • User246900 posted

    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)

    Friday, March 22, 2019 6:21 PM
  • User228132 posted

    @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>
    
    Saturday, March 23, 2019 5:26 PM
  • User245203 posted

    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.

    Thursday, May 30, 2019 4:19 PM
  • User245203 posted

    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;
                    });
                }
    
    Friday, May 31, 2019 8:48 AM
  • User237334 posted

    @kalkoski said: 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);

    Thank you both for this! @kalkoski and @"AlmaJensen.9398"

    Friday, July 12, 2019 4:58 AM
  • User390089 posted

    @kalkoski thanks alooooooooooooooooooot

    Tuesday, March 24, 2020 11:48 PM
  • User381617 posted

    @shaunpryszlak said: 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;
                    });
                }
    

    Could you explain this a bit more? It seems like it should work but what, in fact, is it doing?

    Tuesday, November 17, 2020 4:28 AM
  • User245203 posted

    @Grime said:

    @shaunpryszlak said: 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;
                    });
                }
    

    Could you explain this a bit more? It seems like it should work but what, in fact, is it doing?

    @Grime

    It is quite simple. It is just making the screen redraw itself. It gets the main (UI) thread to hide the ad and then show it again. It is a bit like when you can't see the ad until you rotate the screen. That causes everything to redraw.

    Tuesday, November 17, 2020 10:23 AM
  • User381617 posted

    Thanks, @shaunpryszlak. The rotate issue was what I was trying to solve, which I did last night (Queensland time). I rejigged the XAML to look like this and it just worked!

    ```

            IsVisible="true"
            PersonalizedAds="true"  
            VerticalOptions="EndAndExpand">
    
            <controls:MTAdView.HeightRequest>
                <x:OnIdiom>
                    <x:OnIdiom.Phone>50</x:OnIdiom.Phone>
                    <x:OnIdiom.Tablet>90</x:OnIdiom.Tablet>
                    <x:OnIdiom.Desktop>90</x:OnIdiom.Desktop>
                </x:OnIdiom>
            </controls:MTAdView.HeightRequest>
    
        </controls:MTAdView>
    

    ```

    Tuesday, November 17, 2020 10:20 PM
  • User245203 posted

    @Grime I think the only problem with that is that if there is no ad then you get a blank space.

    Thursday, November 19, 2020 5:28 PM