Để thảo luận và đưa ra ý kiến phản hồi về các sản phẩm của chúng tôi, hãy tham gia kênh Discord chính thức của Ad Manager trong máy chủ Cộng đồng quảng cáo và đo lường của Google.
Biểu ngữ thích ứng là thế hệ tiếp theo của quảng cáo thích ứng, giúp bạn tăng tối đa hiệu suất bằng cách tối ưu hoá kích thước của quảng cáo cho từng thiết bị. Được cải tiến dựa trên biểu ngữ có kích thước cố định vốn chỉ hỗ trợ chiều cao cố định, biểu ngữ thích ứng cho phép nhà phát triển chỉ định chiều rộng của quảng cáo và sử dụng yếu tố này để xác định kích thước của quảng cáo tối ưu.
Để chọn kích thước quảng cáo phù hợp nhất, biểu ngữ thích ứng trong dòng sử dụng chiều cao tối đa thay vì chiều cao cố định. Nhờ đó, biểu ngữ thích ứng sẽ mang lại cơ hội để nâng cao hiệu suất.
Trường hợp nên sử dụng biểu ngữ thích ứng cùng dòng
Biểu ngữ thích ứng cùng dòng là biểu ngữ lớn hơn, cao hơn so với biểu ngữ thích ứng cố định. Loại biểu ngữ này có nhiều loại chiều cao và có thể cao bằng màn hình của thiết bị.
Biểu ngữ thích ứng cùng dòng được thiết kế để nằm trong nội dung có thể cuộn, chẳng hạn như:
Khi triển khai biểu ngữ thích ứng trong ứng dụng của bạn, hãy lưu ý những điểm sau:
Đảm bảo bạn đang sử dụng phiên bản mới nhất của SDK quảng cáo trên thiết bị di động của Google và nếu bạn đang sử dụng tính năng dàn xếp, thì hãy sử dụng phiên bản mới nhất của bộ chuyển đổi dàn xếp.
Kích thước của biểu ngữ thích ứng cùng dòng được thiết kế để hoạt động hiệu quả nhất khi sử dụng toàn bộ chiều rộng có sẵn. Trong hầu hết các trường hợp, đây sẽ là chiều rộng tối đa của màn hình thiết bị mà bạn đang sử dụng. Hãy nhớ cân nhắc vùng an toàn (nếu có).
Bạn có thể cần cập nhật hoặc tạo các mục hàng mới phù hợp với các kích thước thích ứng.
Tìm hiểu thêm.
Các phương thức để thu được kích thước của quảng cáo là
AdSize.getInlineAdaptiveBannerAdSize(int width, int maxHeight)
Khi bạn sử dụng các API biểu ngữ thích ứng cùng dòng, SDK quảng cáo trên thiết bị di động của Google sẽ trả về một AdSize có chiều rộng nhất định và một cờ cùng dòng. Chiều cao là 0 hoặc maxHeight, tuỳ thuộc vào API mà bạn đang sử dụng. Chiều cao thực tế của quảng cáo có sẵn khi quảng cáo được trả về.
Biểu ngữ thích ứng cùng dòng được thiết kế để nằm trong nội dung có thể cuộn. Biểu ngữ này có thể cao bằng màn hình của thiết bị hoặc bị giới hạn theo chiều cao tối đa, tuỳ thuộc vào API.
Triển khai
Làm theo các bước bên dưới để triển khai một biểu ngữ thích ứng cùng dòng đơn giản.
Thu thập kích thước của quảng cáo biểu ngữ thích ứng cùng dòng. Kích thước bạn thu được sẽ dùng để yêu cầu biểu ngữ thích ứng. Để thu được kích thước của quảng cáo thích ứng, hãy đảm bảo rằng bạn:
Thu thập chiều rộng của thiết bị đang dùng theo pixel không phụ thuộc vào mật độ hoặc đặt chiều rộng riêng nếu bạn không muốn sử dụng toàn bộ chiều rộng của màn hình.
Bạn có thể sử dụng MediaQuery.of(context) để thu được chiều rộng của màn hình.
Sử dụng các phương thức tĩnh thích hợp đối với lớp kích thước quảng cáo, chẳng hạn như
AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(int width)
để thu thập đối tượng AdSize thích ứng cùng dòng cho hướng hiện tại.
Nếu muốn giới hạn chiều cao của biểu ngữ, bạn có thể sử dụng phương thức tĩnh AdSize.getInlineAdaptiveBannerAdSize(int width, int maxHeight).
Tạo một đối tượng AdManagerBannerAd có mã đơn vị quảng cáo, kích thước của quảng cáo thích ứng và một đối tượng yêu cầu quảng cáo.
Tải quảng cáo.
Trong lệnh gọi lại onAdLoaded, hãy sử dụng AdManagerBannerAd.getPlatformAdSize() để lấy kích thước quảng cáo trên nền tảng đã cập nhật và cập nhật chiều cao vùng chứa AdWidget.
Ví dụ về mã
Dưới đây là một tiện ích mẫu giúp tải biểu ngữ thích ứng cùng dòng sao cho vừa với
chiều rộng của màn hình, có tính đến phần lồng ghép:
import'package:flutter/material.dart';import'package:google_mobile_ads/google_mobile_ads.dart';/// This example demonstrates inline adaptive banner ads.////// Loads and shows an inline adaptive banner ad in a scrolling view,/// and reloads the ad when the orientation changes.classInlineAdaptiveExampleextendsStatefulWidget{@override_InlineAdaptiveExampleStatecreateState()=>_InlineAdaptiveExampleState();}class_InlineAdaptiveExampleStateextendsState<InlineAdaptiveExample>{staticconst_insets=16.0;AdManagerBannerAd?_inlineAdaptiveAd;bool_isLoaded=false;AdSize?_adSize;lateOrientation_currentOrientation;doubleget_adWidth=>MediaQuery.of(context).size.width-(2*_insets);@overridevoiddidChangeDependencies(){super.didChangeDependencies();_currentOrientation=MediaQuery.of(context).orientation;_loadAd();}void_loadAd()async{await_inlineAdaptiveAd?.dispose();setState((){_inlineAdaptiveAd=null;_isLoaded=false;});// Get an inline adaptive size for the current orientation.AdSizesize=AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(_adWidth.truncate());_inlineAdaptiveAd=AdManagerBannerAd(// TODO: replace with your own ad unit.adUnitId:'/21775744923/example/adaptive-banner',size:size,request:AdManagerAdRequest(),listener:AdManagerBannerAdListener(onAdLoaded:(Adad)async{print('Inline adaptive banner loaded: ${ad.responseInfo}');// After the ad is loaded, get the platform ad size and use it to// update the height of the container. This is necessary because the// height can change after the ad is loaded.AdManagerBannerAdbannerAd=(adasAdManagerBannerAd);finalAdSize?size=awaitbannerAd.getPlatformAdSize();if(size==null){print('Error: getPlatformAdSize() returned null for $bannerAd');return;}setState((){_inlineAdaptiveAd=bannerAd;_isLoaded=true;_adSize=size;});},onAdFailedToLoad:(Adad,LoadAdErrorerror){print('Inline adaptive banner failedToLoad: $error');ad.dispose();},),);await_inlineAdaptiveAd!.load();}/// Gets a widget containing the ad, if one is loaded.////// Returns an empty container if no ad is loaded, or the orientation/// has changed. Also loads a new ad if the orientation changes.Widget_getAdWidget(){returnOrientationBuilder(builder:(context,orientation){if(_currentOrientation==orientation&&
_inlineAdaptiveAd!=null&&
_isLoaded&&
_adSize!=null){returnAlign(child:Container(width:_adWidth,height:_adSize!.height.toDouble(),child:AdWidget(ad:_inlineAdaptiveAd!,),));}// Reload the ad if the orientation changes.if(_currentOrientation!=orientation){_currentOrientation=orientation;_loadAd();}returnContainer();},);}@overrideWidgetbuild(BuildContextcontext)=>Scaffold(appBar:AppBar(title:Text('Inline adaptive banner example'),),body:Center(child:Padding(padding:constEdgeInsets.symmetric(horizontal:_insets),child:ListView.separated(itemCount:20,separatorBuilder:(BuildContextcontext,intindex){returnContainer(height:40,);},itemBuilder:(BuildContextcontext,intindex){if(index==10){return_getAdWidget();}returnText('Placeholder text',style:TextStyle(fontSize:24),);},),),));@overridevoiddispose(){super.dispose();_inlineAdaptiveAd?.dispose();}}
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-09-06 UTC."],[[["\u003cp\u003eInline adaptive banners are responsive ads that optimize size for each device, maximizing performance by using the full available width.\u003c/p\u003e\n"],["\u003cp\u003eThese banners are designed to be placed within scrolling content and can adjust their height to fit the screen or a specified maximum height.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers need to specify the ad width, accounting for device width and safe areas, for optimal sizing.\u003c/p\u003e\n"],["\u003cp\u003eImplementation involves getting the adaptive ad size, creating an \u003ccode\u003eAdManagerBannerAd\u003c/code\u003e object, loading the ad, and updating the container height based on the loaded ad's size.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/ad-manager/mobile-ads-sdk/android/banner/inline-adaptive \"View this page for the Android platform docs.\") [iOS](/ad-manager/mobile-ads-sdk/ios/banner/inline-adaptive \"View this page for the iOS platform docs.\") [Flutter](/ad-manager/mobile-ads-sdk/flutter/banner/inline-adaptive \"View this page for the Flutter platform docs.\")\n\n\u003cbr /\u003e\n\nAdaptive banners are the next generation of responsive ads, maximizing\nperformance by optimizing ad size for each device. Improving on fixed-size\nbanners, which only supported fixed heights, adaptive banners let developers\nspecify the ad-width and use this to determine the optimal ad size.\n\nTo pick the best ad size, inline adaptive banners use maximum instead of fixed\nheights. This results in opportunities for improved performance.\n\nWhen to use inline adaptive banners\n\nInline adaptive banners are larger, taller banners compared to anchored adaptive\nbanners. They are of variable height, and can be as tall as the device screen.\n\nThey are intended to be placed in scrolling content, for example:\n\nPrerequisites\n\n- Follow the instructions from the [Get Started guide](/ad-manager/mobile-ads-sdk/flutter/quick-start) on how to [Import the Mobile Ads Flutter plugin](/ad-manager/mobile-ads-sdk/flutter/quick-start#import_the_mobile_ads_sdk).\n\nBefore you begin **Important:** 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 that are\n| applicable**.\n\nWhen implementing adaptive banners in your app, note these points:\n\n- Ensure you are using the latest version of the Google Mobile Ads SDK, and if\n using mediation, the latest versions of your mediation adapters.\n\n- The inline adaptive banner sizes are designed to work best when using the\n full available width. In most cases, this will be the full width of the\n screen of the device in use. Be sure to take into account applicable safe areas.\n\n- You may need to update or create new line items to work with adaptive sizes.\n [Learn more](https://support.google.com/admanager/answer/9464128).\n\n- The methods for getting the ad size are\n\n - `AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(int width)`\n - `AdSize.getLandscapeInlineAdaptiveBannerAdSize(int width)`\n - `AdSize.getPortraitInlineAdaptiveBannerAdSize(int width)`\n - `AdSize.getInlineAdaptiveBannerAdSize(int width, int maxHeight)`\n- When using the inline adaptive banner APIs, the Google Mobile Ads SDK\n returns an `AdSize` with the given width and an\n inline flag. The height is either zero or `maxHeight`, depending on which\n API you're using. The actual height of the ad is made available when it's\n returned.\n\n- An inline adaptive banner is designed to be placed in scrollable content. The\n banner can be as tall as the device screen or limited by a maximum height,\n depending on the API.\n\nImplementation\n\nFollow the steps below to implement a simple inline adaptive banner.\n\n1. **Get an inline adaptive banner ad size.** The size you get will be used to request the 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. You can use `MediaQuery.of(context)` to get the screen width.\n 2. Use the appropriate static methods on the ad size class, such as `AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(int width)` to get an inline adaptive `AdSize` object for the current orientation.\n 3. If you wish to limit the height of the banner, you can use the static method `AdSize.getInlineAdaptiveBannerAdSize(int width, int maxHeight)`.\n2. Create an `AdManagerBannerAd` object with your ad unit ID, the adaptive ad size, and an ad request object.\n3. Load the ad.\n4. In the `onAdLoaded` callback, use `AdManagerBannerAd.getPlatformAdSize()` to get the updated platform ad size and update the `AdWidget` container height.\n\nCode example\n\nHere's an example widget that loads an inline adaptive banner to fit the\nwidth of the screen, accounting for insets: \n\n import 'package:flutter/material.dart';\n import 'package:google_mobile_ads/google_mobile_ads.dart';\n\n /// This example demonstrates inline adaptive banner ads.\n ///\n /// Loads and shows an inline adaptive banner ad in a scrolling view,\n /// and reloads the ad when the orientation changes.\n class InlineAdaptiveExample extends StatefulWidget {\n @override\n _InlineAdaptiveExampleState createState() =\u003e _InlineAdaptiveExampleState();\n }\n\n class _InlineAdaptiveExampleState extends State\u003cInlineAdaptiveExample\u003e {\n static const _insets = 16.0;\n AdManagerBannerAd? _inlineAdaptiveAd;\n bool _isLoaded = false;\n AdSize? _adSize;\n late Orientation _currentOrientation;\n\n double get _adWidth =\u003e MediaQuery.of(context).size.width - (2 * _insets);\n\n @override\n void didChangeDependencies() {\n super.didChangeDependencies();\n _currentOrientation = MediaQuery.of(context).orientation;\n _loadAd();\n }\n\n void _loadAd() async {\n await _inlineAdaptiveAd?.dispose();\n setState(() {\n _inlineAdaptiveAd = null;\n _isLoaded = false;\n });\n\n // Get an inline adaptive size for the current orientation.\n AdSize size = AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(\n _adWidth.truncate());\n\n _inlineAdaptiveAd = AdManagerBannerAd(\n // TODO: replace with your own ad unit.\n adUnitId: '/21775744923/example/adaptive-banner',\n size: size,\n request: AdManagerAdRequest(),\n listener: AdManagerBannerAdListener(\n onAdLoaded: (Ad ad) async {\n print('Inline adaptive banner loaded: ${ad.responseInfo}');\n\n // After the ad is loaded, get the platform ad size and use it to\n // update the height of the container. This is necessary because the\n // height can change after the ad is loaded.\n AdManagerBannerAd bannerAd = (ad as AdManagerBannerAd);\n final AdSize? size = await bannerAd.getPlatformAdSize();\n if (size == null) {\n print('Error: getPlatformAdSize() returned null for $bannerAd');\n return;\n }\n\n setState(() {\n _inlineAdaptiveAd = bannerAd;\n _isLoaded = true;\n _adSize = size;\n });\n },\n onAdFailedToLoad: (Ad ad, LoadAdError error) {\n print('Inline adaptive banner failedToLoad: $error');\n ad.dispose();\n },\n ),\n );\n await _inlineAdaptiveAd!.load();\n }\n\n /// Gets a widget containing the ad, if one is loaded.\n ///\n /// Returns an empty container if no ad is loaded, or the orientation\n /// has changed. Also loads a new ad if the orientation changes.\n Widget _getAdWidget() {\n return OrientationBuilder(\n builder: (context, orientation) {\n if (_currentOrientation == orientation &&\n _inlineAdaptiveAd != null &&\n _isLoaded &&\n _adSize != null) {\n return Align(\n child: Container(\n width: _adWidth,\n height: _adSize!.height.toDouble(),\n child: AdWidget(\n ad: _inlineAdaptiveAd!,\n ),\n ));\n }\n // Reload the ad if the orientation changes.\n if (_currentOrientation != orientation) {\n _currentOrientation = orientation;\n _loadAd();\n }\n return Container();\n },\n );\n }\n\n @override\n Widget build(BuildContext context) =\u003e Scaffold(\n appBar: AppBar(\n title: Text('Inline adaptive banner example'),\n ),\n body: Center(\n child: Padding(\n padding: const EdgeInsets.symmetric(horizontal: _insets),\n child: ListView.separated(\n itemCount: 20,\n separatorBuilder: (BuildContext context, int index) {\n return Container(\n height: 40,\n );\n },\n itemBuilder: (BuildContext context, int index) {\n if (index == 10) {\n return _getAdWidget();\n }\n return Text(\n 'Placeholder text',\n style: TextStyle(fontSize: 24),\n );\n },\n ),\n ),\n ));\n\n @override\n void dispose() {\n super.dispose();\n _inlineAdaptiveAd?.dispose();\n }\n }"]]