Xamarin 表单自适应横幅广告不会在横向加载



我最近从Galaxy S6升级到Galaxy S21 Ultra,现在AdMob自适应横幅广告将不会以横向方式加载。在S6上它很好,但在S21上我得到了错误:

[Ads]广告加载失败:1

我用来创建广告的代码在这里:

private void NewAdaptiveBannerAd()
{
try
{
adAdaptiveBannerView = new AdAdaptiveBannerView();
adAdaptiveBannerView.Padding = new Thickness(0);
adAdaptiveBannerView.BackgroundColor = (Color)Application.Current.Resources["baseBackground_Light"];
AdGrid.Children.Add(adAdaptiveBannerView, 0, 1);
adAdaptiveBannerView.HeightRequest = getCurrentOrientationAnchoredAdaptiveBannerAdSize(Android.App.Application.Context, (int)(DeviceDisplay.MainDisplayInfo.Width / DeviceDisplay.MainDisplayInfo.Density));
static int getCurrentOrientationAnchoredAdaptiveBannerAdSize(Context context, int adWidth)
{
int var3 = 0;
if (context == null)
{
return 0;
}
else
{
int var7 = 2;
switch (DeviceDisplay.MainDisplayInfo.Orientation)
{
case DisplayOrientation.Unknown: var7 = 0; break;
case DisplayOrientation.Portrait: var7 = 1; break;
case DisplayOrientation.Landscape: var7 = 2; break;
default: return 0;
}
if (var3 == 0)
{
var3 = var7;
}
int var8 = var3 == var7 ? (int)Math.Round((float)DeviceDisplay.MainDisplayInfo.Height / DeviceDisplay.MainDisplayInfo.Density) : (int)Math.Round((float)DeviceDisplay.MainDisplayInfo.Width / DeviceDisplay.MainDisplayInfo.Density);
int var9 = (int)Math.Min(90, Math.Round((float)var8 * 0.15F));
int var10;
if (adWidth > 655)
{
var10 = (int)Math.Round((float)adWidth / 728.0F * 90.0F);
}
else if (adWidth > 632)
{
var10 = 81;
}
else if (adWidth > 526)
{
var10 = (int)Math.Round((float)adWidth / 468.0F * 60.0F);
}
else if (adWidth > 432)
{
var10 = 68;
}
else
{
var10 = (int)Math.Round((float)adWidth / 320.0F * 50.0F);
}
var10 = Math.Max(Math.Min(var10, var9), 50);
return var10;
}
}
}
catch (Exception)
{
Console.WriteLine("Creation of banner ad in SavedCharts failed.");
}
}

adAdaptiveBannerView是在pages类的顶部声明的。getCurrentOrientationAnchoredAdaptiveBannerAdSize函数来自我现在找不到的另一篇文章。

我找不到任何东西来解释这一点,也找不到为什么这两款手机的表现会有所不同(是安卓版本的不同,纵横比不同还是什么?(。在模拟器上测试很困难,因为它没有正确报告方向。

有人知道发生了什么事吗?

我的应用程序本质上主要用于风景模式,所以这个问题意味着很多人可能看不到广告。

PS我使用的是Xamarin.GooglePlayServices.Ads版本119.8.0。我还没能实现版本120,因为没有任何文档或任何东西可以帮助我做到这一点

编辑1:我尝试过有条件地在人像中添加自适应横幅广告,并使用MarcTron.Admob添加标准横幅广告。这不起作用。

我想知道这是否是因为S21 Ultra的显示屏是1440 x 3200像素,纵横比为20:9,而谷歌广告移动无法应对。如果是这样的话,那就太愚蠢了("自适应"?!(。所以我试着在S6(1440x3200(和1600(即一半(的基础上给它一个2560的屏幕宽度,但都不起作用。

编辑2:当我试图将屏幕宽度限制为2560px时,我意识到我犯了一个错误,那就是我只对视图的高度要求这样做,而我也需要对AdMob类本身的AdSize属性这样做。无论如何,就是的问题——自适应横幅广告无法应付3200px宽的显示屏。

谷歌AdMab自适应横幅广告无法处理3200px的屏幕宽度。我不知道实际的限制是什么,但由于它适用于我的另一台屏幕宽度为2560px的设备,我将其限制在这个范围内,比如:

adView.AdSize = AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSize(Android.App.Application.Context, (int)(Math.Min(2560,DeviceDisplay.MainDisplayInfo.Width) / DeviceDisplay.MainDisplayInfo.Density));

并对我的问题中的代码应用了相同的Math.Min((限制器。

有一个稍微不幸的副作用,即横幅广告两侧的间隙(3200-2560(/2=320像素宽。不过这并不违反谷歌的政策(https://developers.google.com/admob/android/banner/adaptive)。

我认为这是谷歌API(或者至少是NuGet软件包(中的一个缺陷,因为一个无法应对真实设备中所有屏幕分辨率的"自适应"广告不符合它的名字。

最新更新