锚定自适应横幅广告
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
自适应横幅广告是新一代自适应广告,可针对每台设备优化广告尺寸,从而最大限度地提升广告效果。自适应横幅广告在智能横幅广告(仅支持固定高度)的基础上进行了改进,您可以指定广告宽度,进而确定最佳广告尺寸。
为了选择最佳广告尺寸,自适应横幅广告采用的是固定宽高比,而不是固定高度。因此,这种横幅广告在不同设备上占据的屏幕区域更为一致,也带来了提升广告效果的机会。
请注意,使用自适应横幅广告时,如果给定设备类型和宽度,则返回的广告尺寸将始终固定不变。在给定设备上测试布局后,便可以确定广告尺寸不会发生变化。不过,横幅广告素材的尺寸在不同设备上可能会有所不同。因此,建议您确保版式可以适应各种广告高度。在极少数情况下,广告素材可能达不到自适应广告的全尺寸,标准尺寸的广告素材将居中显示在广告位中。
自适应横幅广告适用情形
自适应横幅广告可直接替换行业标准的 320x50 横幅广告尺寸以及自适应横幅广告所取代的智能横幅广告格式。
这些横幅广告尺寸常用于锚定横幅广告,锚定横幅广告通常固定在屏幕的顶部或底部展示。对于此类锚定横幅广告,当采用自适应横幅广告格式时,宽高比与标准 320x50 广告大致相当,如以下三张屏幕截图所示:

320x50 横幅广告
|

智能横幅广告
|

自适应横幅广告
|
自适应横幅广告可更好地利用可用的屏幕尺寸。此外,与智能横幅广告相比,自适应横幅广告是一种更好的选择,原因如下:
实现说明
在应用中植入自适应横幅广告时,请注意以下几点:
您必须知道要展示广告的视图的宽度,并且应在设置视图宽度时考虑到设备宽度,以及任何适用的安全区域。
当尺寸较小的广告不能填满广告位时,请务必将广告视图背景设为不透明,以符合 AdMob 政策。
确保您使用的是最新版 Google 移动广告 C++ SDK。对于中介,请使用每个中介适配器的最新版本。
按照自适应横幅广告尺寸的设计,占满可用宽度时效果最佳。在大多数情况下,这指的是所用设备的屏幕全宽。请务必考虑适用的安全区域。
Google 移动广告 C++ SDK 会在 firebase::gma::AdSize
中返回给定宽度对应的经过优化的广告高度。
获取自适应横幅广告尺寸的方法有以下三种:一种适用于横向屏幕,一种适用于纵向屏幕,还有一种适用于执行操作时的屏幕方向。
针对给定设备上的给定宽度返回的广告尺寸始终都相同,因此在给定设备上测试好版式后,就可以确定广告尺寸不会发生变化。
锚定横幅广告的高度始终不会超过设备高度的 15%,也始终不小于 50 磅 (pt)。
快速入门
若要植入简单的自适应锚定横幅广告,请按照以下步骤操作。
获取自适应横幅广告尺寸。您获取的尺寸将用于请求自适应横幅广告。要获取自适应广告尺寸,请务必:
获取所用设备的宽度,或者自行设置宽度(如果您不想使用屏幕的全宽)。
使用 AdSize
类中的相应静态方法(例如 GetCurrentOrientationAnchoredAdaptiveBannerAdSize(uint32_t width)
),获取与所选屏幕方向对应的自适应 AdSize
对象。
使用您创建的自适应 AdSize
在 AdView
上调用 Initialize()
。
下面列出了完整示例。
创建一个 AdRequest
对象,然后使用您准备好的广告视图中的 loadAd()
方法加载横幅广告,具体方式与常规横幅广告请求一样。
示例代码
以下是一个将加载自适应横幅广告的 AdView
示例:
// Determine view width in pixels based on your app's current width on the
// device's screen. This process will vary depending on which windowing toolkit
// you're using.
firebase::gma::AdSize adaptive_ad_size =
AdSize::GetCurrentOrientationAnchoredAdaptiveBannerAdSize(view_width);
// my_ad_parent is a reference to an iOS UIView or an Android Activity.
// This is the parent UIView or Activity of the banner view.
firebase::gma::AdParent ad_parent =
static_cast<firebase::gma::AdParent>(my_ad_parent);
firebase::Future<void> result =
ad_view->Initialize(ad_parent, kBannerAdUnit, adaptive_ad_size);
在本示例中,函数 GetCurrentOrientationAnchoredAdaptiveBannerAdSize(uint32_t width)
用于获取适用于当前界面方向的锚定位置横幅广告的尺寸。要按给定屏幕方向预加载锚定横幅广告,请使用 GetPortraitAnchoredAdaptiveBannerAdSize(uint32_t width)
和 GetLandscapeAnchoredAdaptiveBannerAdSize(uint32_t width)
中的相关函数。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eAdaptive banners optimize ad size for each device, improving performance by using fixed aspect ratios for a consistent screen presence.\u003c/p\u003e\n"],["\u003cp\u003eThey are drop-in replacements for standard 320x50 banners and smart banners, best used as anchored banners (top or bottom of the screen).\u003c/p\u003e\n"],["\u003cp\u003eAdaptive banners offer advantages over smart banners by utilizing provided width for safe areas and adjusting height for optimal display on various devices.\u003c/p\u003e\n"],["\u003cp\u003eImplementation requires knowing the ad view's width (considering device width and safe areas), using an opaque background, and the latest Google Mobile Ads C++ SDK.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can obtain the adaptive banner size using \u003ccode\u003eAdSize\u003c/code\u003e class methods, considering device width and orientation, to initialize and load the ad view.\u003c/p\u003e\n"]]],["Adaptive banners optimize ad size per device using fixed aspect ratios instead of fixed heights, improving performance and screen usage compared to smart banners. Key actions include determining the ad view width, accounting for safe areas, and using `AdSize` methods (e.g., `GetCurrentOrientationAnchoredAdaptiveBannerAdSize`) to get the optimal ad size for a specific orientation. Developers should ensure opaque ad view backgrounds and use the latest SDK. The returned ad size remains consistent on a given device but may differ across devices.\n"],null,["# Anchored adaptive banners\n\nAdaptive banners are the next generation of responsive ads, maximizing\nperformance by optimizing ad size for each device. Improving on smart banners,\nwhich only supported fixed heights, adaptive banners let you specify the\nad-width and use this to determine the optimal ad size.\n\nTo pick the best ad size, adaptive banners use fixed aspect ratios instead of\nfixed heights. This results in banner ads that occupy a more consistent portion\nof the screen across devices and provide opportunities for improved performance.\n\nWhen working with adaptive banners, note that they will always return a\nconstant size for a given device and width. Once you've tested your layout on a\ngiven device, you can be sure that the ad size will not change. However, the\nsize of the banner creative may change across different devices. Consequently,\nit is recommended to ensure your layout can accommodate variances in ad height.\nIn rare cases, the full adaptive size may not be filled and a standard size\ncreative will be centered in this slot instead.\n\nWhen to use adaptive banners\n----------------------------\n\nAdaptive banners are designed to be a drop-in replacement for the industry\nstandard 320x50 banner size, as well as the smart banner format they supersede.\n\nThese banner sizes are commonly used as anchored banners, which are usually\nlocked to the top or bottom of the screen. For such anchored banners, the aspect\nratio when using adaptive banners will be similar to that of a standard 320x50\nad, as can be seen in these screenshots:\n\n|---------------|--------------|-----------------|\n| 320x50 banner | Smart banner | Adaptive banner |\n\nAn adaptive banner makes better use of the available screen size. Additionally,\ncompared to a smart banner, an adaptive banner is a better choice because:\n\n- It uses a provided width rather than full screen width, enabling you to\n account for safe areas.\n\n- It selects an optimal height for the specific device, rather than having a\n constant height across different sized devices, mitigating the effects of\n device fragmentation.\n\nImplementation notes\n--------------------\n\nWhen implementing adaptive banners in your app, keep the following points in\nmind:\n\n- You must know the width of the view that the ad will be placed in, *and this\n should take into account the device width and any safe areas that are\n applicable*.\n\n- Ensure that your ad view background is opaque to be compliant with AdMob\n policies when smaller ad sizes serve that do not fill the ad slot.\n\n- Ensure you are using the latest version of the Google Mobile Ads C++ SDK. For\n mediation, use the latest version of each mediation adapter.\n\n- The adaptive banner sizes are designed to work best when using the full\n available width. In most cases, this will be the full width of the screen of\n the device in use. Be sure to take into account applicable safe areas.\n\n- The Google Mobile Ads C++ SDK returns an optimized ad height for the given\n width in a `firebase::gma::AdSize`.\n\n- There are three methods to get an ad size for adaptive banners---one for\n landscape, one for portrait, and one for the current orientation at the time\n of execution.\n\n- The size returned for a given width on a given device will always be the same,\n hence once you've tested your layout on a given device, you can be sure that\n the ad size will not change.\n\n- Anchored banner height is never larger than 15% of the device's height and\n never smaller than 50 points.\n\nQuick start\n-----------\n\nFollow the steps below to implement a simple adaptive anchor banner.\n\n1. Get an adaptive banner ad size. The size you get will be used to request\n your adaptive banner. To get the adaptive ad size, make sure that you:\n\n 1. Get the width of the device in use, or set your own width if you don't\n want to use the full width of the screen.\n\n 2. Use the appropriate static methods on the `AdSize` class, such as\n `GetCurrentOrientationAnchoredAdaptiveBannerAdSize(uint32_t width)` to\n get an adaptive `AdSize` object for the chosen orientation.\n\n 3. Invoke `Initialize()` on the `AdView` with the adaptive `AdSize` you've\n created.\n\n A full example is included below.\n2. Create an `AdRequest` object and load your banner using the `loadAd()`\n method on your prepared ad view, just like you would with a normal banner\n request.\n\nSample code\n-----------\n\nHere's an example of an `AdView` that will load an adaptive banner: \n\n // Determine view width in pixels based on your app's current width on the\n // device's screen. This process will vary depending on which windowing toolkit\n // you're using.\n\n firebase::gma::AdSize adaptive_ad_size =\n AdSize::GetCurrentOrientationAnchoredAdaptiveBannerAdSize(view_width);\n\n // my_ad_parent is a reference to an iOS UIView or an Android Activity.\n // This is the parent UIView or Activity of the banner view.\n firebase::gma::AdParent ad_parent =\n static_cast\u003cfirebase::gma::AdParent\u003e(my_ad_parent);\n firebase::Future\u003cvoid\u003e result =\n ad_view-\u003eInitialize(ad_parent, kBannerAdUnit, adaptive_ad_size);\n\nHere, the function\n`GetCurrentOrientationAnchoredAdaptiveBannerAdSize(uint32_t width)` is used to\nget the size for a banner in an anchored position for the current interface\norientation. For pre-loading an anchored banner in a given orientation, use the\nrelevant function from `GetPortraitAnchoredAdaptiveBannerAdSize(uint32_t width)`\nand `GetLandscapeAnchoredAdaptiveBannerAdSize(uint32_t width)`."]]