以下示例代码包含一个广告单元 ID,可供您用来请求测试广告。该 ID 已经过专门配置,可针对每个请求返回测试广告(而非实际投放的广告),因此能够安全地使用。
不过,在 Ad Manager 网页界面中注册应用并创建要在应用中使用的广告单元 ID 后,您需要在开发期间明确地将您的设备配置为测试设备。
/21775744923/example/adaptive-banner
创建锚定自适应横幅广告
以下示例展示了如何创建一个锚定在屏幕底部的自适应横幅广告视图:
// Get the device safe width in density-independent pixels.intdeviceWidth=MobileAds.Utils.GetDeviceSafeWidth();// Define the anchored adaptive ad size.AdSizeadaptiveSize=AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(deviceWidth);// Create an anchored adaptive banner view.adManagerBannerView=newAdManagerBannerView("AD_UNIT_ID",adaptiveSize,AdPosition.Bottom);