錨定自動調整橫幅廣告
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
自動調整橫幅廣告是新一代的回應式廣告,能配合裝置調整大小來提升成效。有別於僅支援固定高度的智慧型橫幅廣告,自動調整橫幅廣告可讓您指定廣告寬度,以此決定理想的廣告大小。
為了選擇最適合的廣告大小,自動調整式橫幅廣告採用固定顯示比例,而非固定高度,因此在不同裝置和螢幕大小上顯示橫幅廣告時,所占版面比例會更加一致,有助提升成效。
請注意,對於相同的裝置和寬度設定,自動調整橫幅廣告一律會傳回固定大小的廣告。因此當您在特定裝置上測試過版面配置後,便可確定廣告大小不會再變動。不過,橫幅廣告素材的大小可能會依裝置而異。因此,建議您採用能配合不同廣告高度的版面配置。儘管非常少見,但如果廣告素材無法填滿自動調整式橫幅廣告版位,系統會改為置中顯示標準大小的廣告素材。
先決條件
自動調整橫幅廣告的使用時機
自動調整橫幅廣告將會直接取代業界標準的 320x50 橫幅廣告,以及智慧型橫幅廣告格式。
這些尺寸通常用來做為錨定橫幅廣告,並固定顯示在畫面頂端或底部。
對於此類錨定橫幅廣告,自動調整橫幅廣告會採用與標準 320x50 廣告相似的顯示比例,如以下三個範例所示:

320x50 橫幅廣告
|

自動調整橫幅廣告
|

智慧型橫幅廣告
|
自動調整橫幅廣告不僅能更有效運用可用螢幕空間,並且與智慧型橫幅廣告相比,還具有以下優勢:
導入注意事項
在應用程式中導入自動調整橫幅廣告時,請注意以下事項:
- 您必須知道廣告所在檢視區塊的寬度,且計算時應考量裝置寬度,並注意保留安全區域或避開螢幕凹口。
- 務必採用不透明的廣告檢視區塊背景,避免因廣告尺寸不足以填滿版位而違反 AdMob 政策。
- 確認所用的 Google Mobile Ads Unity 外掛程式為最新版本。如果使用中介服務,請確保所有中介服務轉接程式均為最新版本。
- 自動調整橫幅廣告在採用最大可用寬度時效果最佳,這通常是指裝置螢幕的全寬。請務必考慮到需保留的安全區域。
- 使用自動調整型 AdSize API 時,Google Mobile Ads SDK 會依給定寬度選擇最合適的橫幅廣告高度。
- 取得自動調整廣告尺寸的方法有以下三種:
AdSize.GetLandscapeAnchoredAdaptiveBannerAdSizeWithWidth
(用於橫向螢幕)、AdSize.GetPortraitAnchoredAdaptiveBannerAdSizeWithWidth
(用於直向螢幕),以及 AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth
(用於執行操作時的螢幕方向)。
- 在同一裝置上採用相同寬度設定時,系統一律會傳回固定大小的廣告,因此當您在特定裝置上測試過版面配置後,便可確定廣告大小不會再變動。
- 錨定橫幅廣告的高度上限為裝置高度的 15%,或是 90 個密度獨立像素 (以較小者為準),下限則為 50 個密度獨立像素。
- 如要投放全寬橫幅廣告,您可以改用
AdSize.FullWidth
標記,而非提供具體寬度。
快速入門
導入簡易自動調整錨定橫幅廣告的步驟如下:
- 取得自動調整橫幅廣告尺寸,用於請求該類廣告。如要取得尺寸,請確實完成下列操作:
- 取得目前裝置的寬度 (以密度獨立像素計算);如果不想使用螢幕全寬,也可以自行設定寬度。
由於
Screen.width
等 Unity API 會傳回絕對像素值,因此您必須將該值除以裝置縮放比例 (可透過 MobileAds.Utils.GetDeviceScale()
取得)。
- 如要投放全寬橫幅廣告,請使用
AdSize.FullWidth
標記。
- 依據廣告尺寸類別使用適當的靜態方法 (例如
AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(width)
),取得符合目前螢幕方向的自動調整 AdSize
物件。
- 建立
BannerView
物件,並指定廣告單元 ID、自動調整大小,以及廣告相關位置。
- 建立廣告請求物件,然後在您準備的廣告檢視區塊中,使用
LoadAd()
方法載入橫幅廣告。操作方法與一般橫幅廣告請求相同。
程式碼範例
以下指令碼範例可配合螢幕寬度,載入及重新載入自動調整橫幅廣告,且不會占用安全區域:
using UnityEngine;
using System;
using GoogleMobileAds.Api;
public class AdaptiveBannerSample : MonoBehaviour
{
private BannerView _bannerView;
// Use this for initialization
void Start()
{
// Set your test devices.
// https://developers.google.com/ad-manager/mobile-ads-sdk/unity/test-ads
RequestConfiguration requestConfiguration = new RequestConfiguration
{
TestDeviceIds = new List<string>
{
AdRequest.TestDeviceSimulator,
// Add your test device IDs (replace with your own device IDs).
#if UNITY_IPHONE
"96e23e80653bb28980d3f40beb58915c"
#elif UNITY_ANDROID
"75EF8D155528C04DACBBA6F36F433035"
#endif
}
};
MobileAds.SetRequestConfiguration(requestConfiguration);
// Initialize the Google Mobile Ads SDK.
MobileAds.Initialize((InitializationStatus status) =>
{
RequestBanner();
});
}
public void OnGUI()
{
GUI.skin.label.fontSize = 60;
Rect textOutputRect = new Rect(
0.15f * Screen.width,
0.25f * Screen.height,
0.7f * Screen.width,
0.3f * Screen.height);
GUI.Label(textOutputRect, "Adaptive Banner Example");
}
private void RequestBanner()
{
// These ad units are configured to always serve test ads.
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-3212738706492790/6113697308";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-3212738706492790/5381898163";
#else
string adUnitId = "unexpected_platform";
#endif
// Clean up banner ad before creating a new one.
if (_bannerView != null)
{
_bannerView.Destroy();
}
AdSize adaptiveSize =
AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(AdSize.FullWidth);
_bannerView = new BannerView(adUnitId, adaptiveSize, AdPosition.Bottom);
// Register for ad events.
_bannerView.OnBannerAdLoaded += OnBannerAdLoaded;
_bannerView.OnBannerAdLoadFailed += OnBannerAdLoadFailed;
AdRequest adRequest = new AdRequest();
// Load a banner ad.
_bannerView.LoadAd(adRequest);
}
#region Banner callback handlers
private void OnBannerAdLoaded(object sender, EventArgs args)
{
Debug.Log("Banner view loaded an ad with response : "
+ _bannerView.GetResponseInfo());
Debug.Log("Ad Height: {0}, width: {1}",
_bannerView.GetHeightInPixels(),
_bannerView.GetWidthInPixels());
}
private void OnBannerAdLoadFailed(LoadAdError error)
{
Debug.LogError("Banner view failed to load an ad with error : "
+ error);
}
#endregion
}
以下範例使用 AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth
函式,取得在當前介面方向中,錨定位置的橫幅廣告尺寸。如要在特定螢幕方向預先載入錨定橫幅廣告,請使用 AdSize.GetPortraitAnchoredAdaptiveBannerAdSizeWithWidth
和 AdSize.GetLandscapeAnchoredAdaptiveBannerAdSizeWithWidth
的相關函式。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-31 (世界標準時間)。
[null,null,["上次更新時間:2025-08-31 (世界標準時間)。"],[[["\u003cp\u003eAdaptive banners maximize ad performance by optimizing the ad size for each device, using fixed aspect ratios for the best ad size.\u003c/p\u003e\n"],["\u003cp\u003eThey are a drop-in replacement for standard 320x50 banners and smart banners, designed for anchored positions (top or bottom of the screen).\u003c/p\u003e\n"],["\u003cp\u003eAdaptive banners offer advantages over smart banners: using any provided width (accounting for safe areas), selecting optimal height per device (reducing fragmentation).\u003c/p\u003e\n"],["\u003cp\u003eWhen implementing, consider the view's width (including safe areas), use an opaque background, and use the latest SDK and adapter versions.\u003c/p\u003e\n"],["\u003cp\u003eTo get an adaptive banner size, use the provided static methods, such as \u003ccode\u003eAdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(width)\u003c/code\u003e, after calculating the device or desired width.\u003c/p\u003e\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 supported only fixed heights, adaptive banners let you specify the\nad width and use this to determine the optimal ad size.\n\nTo choose 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 provides opportunities for improved\nperformance.\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,\nwe recommend that your layout accommodate variances in ad height. In rare cases,\nthe full adaptive size may not be filled and a standard size creative will be\ncentered in this slot instead.\n\nPrerequisites\n-------------\n\n- [Import the Mobile Ads Unity plugin](/ad-manager/mobile-ads-sdk/unity/quick-start#import_the_mobile_ads_unity_plugin)\n\n- [Include the Mobile Ads SDK](/ad-manager/mobile-ads-sdk/unity/quick-start#include_the_mobile_ads_sdk)\n\nWhen to use adaptive banners\n----------------------------\n\nAdaptive banners are designed to be a drop-in replacement for both the industry\nstandard 320x50 banner size and the smart banner format which they supersede.\n\nThese banner sizes are commonly used as anchored banners, which are usually\nlocked to the top or bottom of the screen.\n\nFor such anchored banners, the aspect ratio when using adaptive banners will be\nsimilar to that of a standard 320x50 ad, as can be seen in the three examples\nbelow:\n\n|---------------|-----------------|--------------|\n| 320x50 banner | Adaptive banner | Smart banner |\n\nThe 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 any width you provide, rather than forcing the width to be full\n screen, enabling you to account for the safe area on iOS, and display cutouts\n on Android.\n\n- It selects an optimal height for the specific device, rather than having a\n constant height across different size 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 mind:\n\n- You must know the width of the view that the ad will be placed in, **and this should take into account the device width and any safe areas or\n cutouts that are applicable**.\n- Ensure that your ad view background is opaque to be compliant with AdMob policies when smaller ad sizes serve that do not fill the ad slot.\n- Ensure you are using the latest version of the Google Mobile Ads Unity plugin. For mediation, use the latest version of each mediation adapter.\n- The adaptive banner sizes are designed to work best when using the full available width. In most cases, this will be the full width of the screen of the device in use. Be sure to take into account applicable safe areas.\n- The Google Mobile Ads SDK will size the banner with an optimized ad height for the given width when using the adaptive AdSize APIs.\n- There are three methods to get an ad size for adaptive: `AdSize.GetLandscapeAnchoredAdaptiveBannerAdSizeWithWidth` for landscape, `AdSize.GetPortraitAnchoredAdaptiveBannerAdSizeWithWidth` for portrait, and `AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth` for the current orientation at the time of execution.\n- The size returned for a given width on a given device will always be the same, hence once you've tested your layout on a given device, you can be sure that the ad size will not change.\n- Anchored banner height is never larger than the lesser of 15% of the device's height or 90 density independent pixels and never smaller than 50 density independent pixels.\n- For full width banners, you can use the `AdSize.FullWidth` flag instead of supplying a specific width.\n\nQuickstart\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 your adaptive banner. To get the adaptive ad size, make sure that you:\n 1. Get the width of the device in use in density independent pixels, or set your own width if you don't want to use the full width of the screen. Since Unity APIs such as `Screen.width` return absolute pixels, you need to divide by device scale (retrievable from `MobileAds.Utils.GetDeviceScale()`).\n 2. Use the `AdSize.FullWidth` flag for full width banners.\n 3. Use the appropriate static methods on the ad size class, such as `AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(width)` to get an adaptive `AdSize` object for the current orientation.\n2. Create a `BannerView` object with your ad unit ID, the adaptive size, and the relevant position for your ad.\n3. Create an ad request object and load your banner using the `LoadAd()` method on your prepared ad view, just like you would with a normal banner request.\n\nCode example\n------------\n\nHere's an example script that loads and reloads an adaptive banner to fit the\nwidth of the screen, taking into account safe area: \n\n using UnityEngine;\n using System;\n using GoogleMobileAds.Api;\n\n public class AdaptiveBannerSample : MonoBehaviour\n {\n private BannerView _bannerView;\n\n // Use this for initialization\n void Start()\n {\n // Set your test devices.\n // https://developers.google.com/ad-manager/mobile-ads-sdk/unity/test-ads\n RequestConfiguration requestConfiguration = new RequestConfiguration\n {\n TestDeviceIds = new List\u003cstring\u003e\n {\n AdRequest.TestDeviceSimulator,\n // Add your test device IDs (replace with your own device IDs).\n #if UNITY_IPHONE\n \"96e23e80653bb28980d3f40beb58915c\"\n #elif UNITY_ANDROID\n \"75EF8D155528C04DACBBA6F36F433035\"\n #endif\n }\n };\n MobileAds.SetRequestConfiguration(requestConfiguration);\n\n // Initialize the Google Mobile Ads SDK.\n MobileAds.Initialize((InitializationStatus status) =\u003e\n {\n RequestBanner();\n });\n }\n\n public void OnGUI()\n {\n GUI.skin.label.fontSize = 60;\n Rect textOutputRect = new Rect(\n 0.15f * Screen.width,\n 0.25f * Screen.height,\n 0.7f * Screen.width,\n 0.3f * Screen.height);\n GUI.Label(textOutputRect, \"Adaptive Banner Example\");\n }\n\n private void RequestBanner()\n {\n // These ad units are configured to always serve test ads.\n #if UNITY_EDITOR\n string adUnitId = \"unused\";\n #elif UNITY_ANDROID\n string adUnitId = \"ca-app-pub-3212738706492790/6113697308\";\n #elif UNITY_IPHONE\n string adUnitId = \"ca-app-pub-3212738706492790/5381898163\";\n #else\n string adUnitId = \"unexpected_platform\";\n #endif\n\n // Clean up banner ad before creating a new one.\n if (_bannerView != null)\n {\n _bannerView.Destroy();\n }\n\n AdSize adaptiveSize =\n AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(AdSize.FullWidth);\n\n _bannerView = new BannerView(adUnitId, adaptiveSize, AdPosition.Bottom);\n\n // Register for ad events.\n _bannerView.OnBannerAdLoaded += OnBannerAdLoaded;\n _bannerView.OnBannerAdLoadFailed += OnBannerAdLoadFailed;\n\n AdRequest adRequest = new AdRequest();\n\n // Load a banner ad.\n _bannerView.LoadAd(adRequest);\n }\n\n #region Banner callback handlers\n\n private void OnBannerAdLoaded(object sender, EventArgs args)\n {\n Debug.Log(\"Banner view loaded an ad with response : \"\n + _bannerView.GetResponseInfo());\n Debug.Log(\"Ad Height: {0}, width: {1}\",\n _bannerView.GetHeightInPixels(),\n _bannerView.GetWidthInPixels());\n }\n\n private void OnBannerAdLoadFailed(LoadAdError error)\n {\n Debug.LogError(\"Banner view failed to load an ad with error : \"\n + error);\n }\n\n #endregion\n }\n\nHere the function\n`AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth` is used\nto get 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 `AdSize.GetPortraitAnchoredAdaptiveBannerAdSizeWithWidth`\nand `AdSize.GetLandscapeAnchoredAdaptiveBannerAdSizeWithWidth`."]]