Quảng cáo biểu ngữ thích ứng cùng dòng
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Chọn nền tảng:
Android
iOS
Flutter
Biểu ngữ thích ứng cho phép bạn chỉ định chiều rộng của quảng cáo để xác định kích thước quảng cáo tối ưu. Biểu ngữ thích ứng cũng tối đa hoá hiệu suất bằng cách tối ưu hoá kích thước quảng cáo cho từng thiết bị. Phương pháp này mang lại cơ hội để nâng cao hiệu suất.
So với biểu ngữ thích ứng cố định, biểu ngữ thích ứng cùng dòng có kích thước lớn hơn, chiều cao cao hơn và sử dụng chiều cao thay đổi thay vì chiều cao cố định. Biểu ngữ thích ứng trong dòng có chiều cao thay đổi và có thể bao gồm toàn bộ màn hình hoặc chiều cao tối đa mà bạn chỉ định.
Bạn đặt biểu ngữ thích ứng cùng dòng trong nội dung có thể cuộn, chẳng hạn như:

Trước khi bắt đầu
Trước khi tiếp tục, hãy đảm bảo bạn đã hoàn tất hướng dẫn bắt đầu, Quảng cáo biểu ngữ.
Triển khai biểu ngữ thích ứng
Không giống như biểu ngữ thích ứng cố định, biểu ngữ thích ứng cùng dòng tải bằng kích thước biểu ngữ thích ứng cùng dòng. Để tạo kích thước quảng cáo thích ứng cùng dòng, hãy hoàn tất các bước sau:
Biết chiều rộng của thiết bị mà bạn đang sử dụng hoặc đặt chiều rộng riêng nếu bạn không muốn sử dụng chiều rộng toàn màn hình.
Kotlin
private val adWidth: Int
get() {
val displayMetrics = resources.displayMetrics
val adWidthPixels =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val windowMetrics: WindowMetrics = this.windowManager.currentWindowMetrics
windowMetrics.bounds.width()
} else {
displayMetrics.widthPixels
}
val density = displayMetrics.density
return (adWidthPixels / density).toInt()
}
Java
public int getAdWidth() {
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
int adWidthPixels = displayMetrics.widthPixels;
if (VERSION.SDK_INT >= VERSION_CODES.R) {
WindowMetrics windowMetrics = this.getWindowManager().getCurrentWindowMetrics();
adWidthPixels = windowMetrics.getBounds().width();
}
float density = displayMetrics.density;
return (int) (adWidthPixels / density);
}
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(Context context, int width)
để thu thập đối tượng kích thước quảng cáo thích ứng cùng dòng cho hướng đã chọn.
Kotlin
val adView = AdView(this@MainActivity)
adView.setAdSize(AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(this, adWidth))
Java
final AdView adView = new AdView(MainActivity.this);
adView.setAdSize(AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(this, getAdWidth()));
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:
- Kích thước của biểu ngữ thích ứng cùng dòng 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, kích thước này là toàn bộ chiều rộng của màn hình thiết bị đang dùng hoặc toàn bộ chiều rộng của nội dung gốc trên biểu ngữ. Bạn phải biết chiều rộng của khung hiển thị để đặt quảng cáo, chiều rộng của thiết bị, chiều rộng của nội dung gốc và các vùng an toàn (nếu có).
Định hướng kích thước biểu ngữ thích ứng cùng dòng
Để tải trước một quảng cáo biểu ngữ thích ứng cùng dòng cho một hướng cụ thể, hãy sử dụng các phương thức sau:
Nếu ứng dụng của bạn hỗ trợ cả chế độ xem dọc và ngang, đồng thời bạn muốn tải trước một quảng cáo biểu ngữ thích ứng theo hướng hiện tại, hãy sử dụng AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(Context context, int width)
Phương thức này tải một quảng cáo theo hướng hiện tại.
Giới hạn chiều cao của biểu ngữ thích ứng cùng dòng
Theo mặc định, biểu ngữ thích ứng cùng dòng được khởi tạo mà không có giá trị maxHeight
sẽ có maxHeight
bằng chiều cao của thiết bị. Để giới hạn chiều cao của biểu ngữ thích ứng cùng dòng, hãy sử dụng phương thức AdSize.getInlineAdaptiveBannerAdSize(int width, int maxHeight)
.
Tài nguyên khác
Ví dụ trên GitHub
Tải ứng dụng mẫu xuống để xem biểu ngữ thích ứng cùng dòng hoạt động.
Java
Kotlin
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-31 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-31 UTC."],[[["\u003cp\u003eAdaptive banners optimize ad size for each device to maximize performance by letting you specify the ad width.\u003c/p\u003e\n"],["\u003cp\u003eInline adaptive banners, placed within scrolling content, are larger, taller, and use variable heights compared to anchored adaptive banners.\u003c/p\u003e\n"],["\u003cp\u003eYou can get an inline adaptive banner ad size using the \u003ccode\u003eAdSize\u003c/code\u003e class's static methods with device width or a custom width.\u003c/p\u003e\n"],["\u003cp\u003eFor specific orientation preloading or limiting banner height, utilize dedicated \u003ccode\u003eAdSize\u003c/code\u003e methods like \u003ccode\u003egetPortraitInlineAdaptiveBannerAdSize\u003c/code\u003e or \u003ccode\u003egetInlineAdaptiveBannerAdSize\u003c/code\u003e.\u003c/p\u003e\n"]]],["Inline adaptive banners, designed for scrolling content, allow specifying ad width for optimal sizing and performance. To implement, determine the device or desired ad width. Then, use methods like `AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize` or `AdSize.getInlineAdaptiveBannerAdSize` to obtain an ad size object. Finally, load an ad using `AdView` and `AdRequest`. You may limit the ad's height, and specific orientation methods are available to load the ad.\n"],null,["Select platform: [Android](/admob/android/banner/inline-adaptive \"View this page for the Android platform docs.\") [iOS](/admob/ios/banner/inline-adaptive \"View this page for the iOS platform docs.\") [Flutter](/admob/flutter/banner/inline-adaptive \"View this page for the Flutter platform docs.\")\n\n\u003cbr /\u003e\n\nAdaptive banners let you specify the width of an ad to determine the optimal\nad size. Adaptive banners also maximize performance by optimizing the ad size\nfor each device. This approach results in opportunities for\nimproved performance.\n\nCompared to anchored adaptive banners, inline adaptive banners are larger,\ntaller, and use variable instead of fixed heights. Inline adaptive banners are\nof variable height, and might encompass the entire screen or a maximum height\nthat you specify.\n\nYou place inline adaptive banners in scrolling content, for example:\n\nBefore you begin\n\nBefore continuing, make sure you have completed the getting started guide,\n[Banner ads](/admob/android/banner).\n\nImplement adaptive banners\n\nUnlike anchored adaptive banners, inline adapter banners load using an inline\nadaptive banner size. To create an inline adaptive ad size, complete the\nfollowing:\n\n1. Get the width of the device in use, or set your own width if you don't want\n to use the full width of the screen.\n\n Kotlin \n\n private val adWidth: Int\n get() {\n val displayMetrics = resources.displayMetrics\n val adWidthPixels =\n if (Build.VERSION.SDK_INT \u003e= Build.VERSION_CODES.R) {\n val windowMetrics: WindowMetrics = this.windowManager.currentWindowMetrics\n windowMetrics.bounds.width()\n } else {\n displayMetrics.widthPixels\n }\n val density = displayMetrics.density\n return (adWidthPixels / density).toInt()\n } \n https://github.com/googleads/googleads-mobile-android-examples/blob/ccc290a583d7f552bdcf81ea76adc05beaa43f0b/kotlin/advanced/InlineAdaptiveBannerExample/app/src/main/java/com/google/android/gms/example/inlineadaptivebannerexample/MainActivity.kt#L70-L83\n\n Java \n\n public int getAdWidth() {\n DisplayMetrics displayMetrics = getResources().getDisplayMetrics();\n int adWidthPixels = displayMetrics.widthPixels;\n\n if (VERSION.SDK_INT \u003e= VERSION_CODES.R) {\n WindowMetrics windowMetrics = this.getWindowManager().getCurrentWindowMetrics();\n adWidthPixels = windowMetrics.getBounds().width();\n }\n\n float density = displayMetrics.density;\n return (int) (adWidthPixels / density);\n } \n https://github.com/googleads/googleads-mobile-android-examples/blob/ccc290a583d7f552bdcf81ea76adc05beaa43f0b/java/advanced/InlineAdaptiveBannerExample/app/src/main/java/com/google/android/gms/example/inlineadaptivebannerexample/MainActivity.java#L133-L145\n\n2. Use the appropriate static methods on the ad size class, such as\n\n `AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(Context context, int width)`\n\n to get an inline adaptive ad size object for the chosen orientation.\n\n Kotlin \n\n val adView = AdView(this@MainActivity)\n adView.setAdSize(AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(this, adWidth)) \n https://github.com/googleads/googleads-mobile-android-examples/blob/ccc290a583d7f552bdcf81ea76adc05beaa43f0b/kotlin/advanced/InlineAdaptiveBannerExample/app/src/main/java/com/google/android/gms/example/inlineadaptivebannerexample/MainActivity.kt#L120-L121\n\n Java \n\n final AdView adView = new AdView(MainActivity.this);\n adView.setAdSize(AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(this, getAdWidth())); \n https://github.com/googleads/googleads-mobile-android-examples/blob/ccc290a583d7f552bdcf81ea76adc05beaa43f0b/java/advanced/InlineAdaptiveBannerExample/app/src/main/java/com/google/android/gms/example/inlineadaptivebannerexample/MainActivity.java#L154-L155\n\n\u003cbr /\u003e\n\nWhen implementing adaptive banners in your app, note these points:\n\n- The inline adaptive banner sizes work best when using the full available width. In most cases, this size is the full width of the device screen in use, or the full width of the banner's parent content. You must know the width of the view to place in the ad, the device width, the parent content width, and applicable safe areas.\n\nOrient inline adaptive banner size\n\nTo preload an inline adaptive banner ad for a specific orientation, use the\nfollowing methods:\n\n- [`AdSize.getPortraitInlineAdaptiveBannerAdSize(Context context, int width)`](/admob/android/reference/com/google/android/gms/ads/AdSize#getPortraitInlineAdaptiveBannerAdSize(android.content.Context,int))\n\n- [`AdSize.getLandscapeInlineAdaptiveBannerAdSize(Context context, int width)`](/admob/android/reference/com/google/android/gms/ads/AdSize#getLandscapeInlineAdaptiveBannerAdSize(android.content.Context,int))\n\nIf your app supports both portrait and landscape views, and you want to preload\nan adaptive banner ad in the current orientation, use\n\n[`AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(Context context, int width)`](/admob/android/reference/com/google/android/gms/ads/AdSize#getCurrentOrientationInlineAdaptiveBannerAdSize(android.content.Context,int))\n\nThis method loads an ad in the current orientation.\n\nLimit inline adaptive banner height\n\nBy default, inline adaptive banners instantiated without a `maxHeight` value\nhave a `maxHeight` equal to the device height. To limit the inline adaptive\nbanner height, use the\n\n[`AdSize.getInlineAdaptiveBannerAdSize(int width, int maxHeight)`](/admob/android/reference/com/google/android/gms/ads/AdSize#getInlineAdaptiveBannerAdSize(int,int))\n\nmethod.\n\nAdditional resources\n\nExamples on GitHub\n\nDownload the sample application to see inline adaptive banners in action.\n\n[Java](//github.com/googleads/googleads-mobile-android-examples/tree/main/java/advanced/InlineAdaptiveBannerExample)\n[Kotlin](//github.com/googleads/googleads-mobile-android-examples/tree/main/kotlin/advanced/InlineAdaptiveBannerExample)\n\n\u003cbr /\u003e"]]