unity-game-engine - 如何在屏幕中央显示 Unity Google AdMob 横幅

标签 unity-game-engine admob googleads-mobile-unity

我有一个 Google AdMob 横幅,我想将其显示在自定义位置。下面的行在我的中工作得很好...

...
    bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);
...

尽管当我想将横幅放置在自定义位置时,它永远不会显示在屏幕上。我正在做:

...
    int w = 0;
    int h = Screen.height/2;

    bannerView = new BannerView(adUnitId, AdSize.Banner, w, -h);
...

我做错了什么?

AdMob 横幅广告的文档可以在此处找到:https://developers.google.com/admob/unity/banner

非常感谢任何帮助! :)

最佳答案

正如您提供的文档所述:

The top-left corner of the BannerView will be positioned at the x and y values passed to the constructor, where the origin is the top-left of the screen.

您的错误可能是您向 y 参数传递了负值,导致 BannerView 位于屏幕上边框之外。
因此,如果您希望横幅 View 仅按高度居中,您的代码应如下所示:

...
int w = 0;
int h = Screen.height/2;

bannerView = new BannerView(adUnitId, AdSize.Banner, w, h);
...

请注意,您没有考虑 BannerView 的实际高度。为了让它居中并考虑到它的高度,这应该可行:

...
int w = 0;
int bannerHeight = 50; //Because AdSize.Banner measures 320x50
int h = Screen.height/2 - bannerHeight/2;

bannerView = new BannerView(adUnitId, AdSize.Banner, w, h);
...

Banner sizes documentation

关于unity-game-engine - 如何在屏幕中央显示 Unity Google AdMob 横幅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52155327/

相关文章:

java - exoplayer 不玩添加并崩溃了

unity-game-engine - 当我制作 WebGl 链接时,它显示了此错误:移动设备不支持 WebGL 构建。方 block 跑者

android - 可变屏幕分辨率 Sprite 不缩放统一

c# - 从 Unity 到 Firebase 的简单图像上传不起作用

android - 在 Unity 应用程序中获取 Google Glass 手势?

iOS - 如何将 GADBannerView 添加到 UICollectionReusableView

android - ViewTreeObserver 中的 IndexOutOfBoundsException

android - Super.onActivityCreated 和 getview 不适用于 ActionBarActivity