原生样式
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
借助原生样式设置,Google Ad Manager 可以根据您在相应产品中指定的原生样式来处理原生广告的呈现。首先,指定尺寸和定位条件。
然后,添加 HTML、CSS 和 JavaScript 代码,以定义自适应且可在所有屏幕上以高质量显示的广告。您无需执行任何呈现操作;Ad Manager 会自动为目标平台应用合适的原生样式。原生样式与横幅广告一样,使用 AdManagerAdView
进行实现。它们可与预先确定的固定广告尺寸或运行时确定的自适应广告尺寸搭配使用。
前提条件
- Google 移动广告 Flutter 插件 0.13.6 或更高版本
本指南假定您已经掌握了 Google 移动广告 SDK 的一些应用知识。如果尚未掌握,不妨先通读我们的使用入门指南。
固定尺寸
借助固定尺寸的原生广告样式,您可以控制原生广告的宽度和高度。如需设置固定大小,请按以下步骤操作:
在 Ad Manager 界面中创建订单项,然后从 Size
字段下拉菜单中选择一种预定义尺寸。
加载与您在第 1 步中设置的大小相同的 AdManagerBannerAd
。
如需了解如何实例化和加载广告,请参阅横幅广告文档。您可以在横幅广告尺寸部分查看尺寸及其对应的 AdSize
常量列表。
以下示例展示了如何指定固定尺寸,例如 MEDIUM_RECTANGLE
(300x250) 广告尺寸:
AdManagerBannerAd ad = AdManagerBannerAd(
adUnitId: '<your-ad-unit>',
sizes: <AdSize>[AdSize.mediumRectangle],
request: AdManagerAdRequest(),
);
自适应尺寸
在某些情况下,固定大小可能不合适。例如,您可能希望广告的宽度与应用的内容保持一致,但需要其高度动态调整以适应广告的内容。如需处理这种情况,您可以在 Ad Manager 界面中将 Fluid
指定为广告尺寸,这表示广告尺寸是在应用的运行时确定的。SDK 提供了一个特殊的 AdSize
常量 FLUID
来处理这种情况。自适应广告尺寸的高度是根据发布商定义的宽度动态确定的,这样平台广告视图就可以调整其高度,使其与广告素材的高度一致。
流体请求
使用 FluidAdManagerBannerAd
请求自适应广告:
final fluidAd = FluidAdManagerBannerAd(
adUnitId: '<your-ad-unit>',
request: AdManagerAdRequest(),
listener: AdManagerBannerAdListener(
onAdLoaded: (Ad ad) {
print('$_fluidAd loaded.');
},
onAdFailedToLoad: (Ad ad, LoadAdError error) {
print('$_fluidAd failedToLoad: $error');
ad.dispose();
},
),
展示流式广告
广告加载完毕后,使用 FluidAdWidget
展示流体广告。它会调整其高度,以匹配底层平台广告视图:
FluidAdWidget(
width: <your-width>,
ad: fluidAd,
);
如需查看 Ad Manager 自适应广告尺寸的示例实现,请参阅 Github 上的示例应用。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-06-11。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-06-11。"],[[["Native style settings in Google Ad Manager allow you to customize the look and feel of your native ads using HTML, CSS, and JavaScript for a seamless user experience."],["You can define fixed-size native ads by specifying their dimensions in the Ad Manager UI and using corresponding `AdSize` constants when loading the ad in your app."],["Alternatively, fluid-size native ads dynamically adjust their height based on the width you provide, ensuring responsiveness across different screens using the `FluidAdManagerBannerAd` and `FluidAdWidget`."],["To implement native ads, you need Google Mobile Ads Flutter Plugin version 0.13.6 or higher and basic familiarity with the Google Mobile Ads SDK."]]],["Google Ad Manager renders native ads based on specified styles. Users define ad size and targeting, then add HTML, CSS, and JavaScript for responsive design. Fixed ad sizes are set in the Ad Manager UI and loaded using `AdManagerBannerAd` with corresponding `AdSize` constants. Fluid ads use `Fluid` in the UI and the `FLUID` constant, with `FluidAdManagerBannerAd` for requests and `FluidAdWidget` for display, dynamically adjusting the height.\n"]]