About Admob adaptive banner.

104 views
Skip to first unread message

dersekranda

unread,
Apr 12, 2025, 7:52:15 PM4/12/25
to Google Mobile Ads SDK Developers
Hello. I am currently using fixed banner ads. I want to switch to adaptive ads. I am currently in the testing phase. I would like to ask a few questions: Due to the content of my application, I do not want to show ads higher than 140 px. In other words, I will adjust the ad height so that it does not exceed 140 px with the calculations I will give below. Also, the height will be adjusted according to the device's aspect ratio with my calculations. If I set 50 dp, a very thin small ad appears on tablets. Are the calculations below in accordance with admob policies? Also, is using 90% of the width instead of the entire width also in accordance with the policies?

private fun getAdSize(): AdSize {
val displayMetrics = resources.displayMetrics
val density = displayMetrics.density
val screenWidthPixels = displayMetrics.widthPixels
val screenHeightPixels = displayMetrics.heightPixels

// Calculate 80% of the screen (width)
val targetWidth = (screenWidthPixels * 1.00).toInt()
val adWidth = (targetWidth / density).toInt()

// Calculate the aspect ratio of the screen
val aspectRatio = screenWidthPixels.toFloat() / screenHeightPixels.toFloat()

// Target aspect ratio of the canvas (e.g. 1440/800 = 1.8)
val targetAspectRatio = 1440f / 800f // 1.8

// Ad determine height according to aspect ratio
// aspectRatio can vary between 0.5 (narrow phone) and 2.0 (wide tablet)
// scale aspectRatio to 50 dp for 0.5 and 120 dp for 2.0
val minAdHeight = 50
val maxAdHeight = 120
val adHeight = minAdHeight + ((maxAdHeight - minAdHeight) * ((aspectRatio - 0.5f) / (2.0f - 0.5f))).toInt()

// Height should not exceed 150 px
val maxHeightPx = 140
val maxHeightDp = (maxHeightPx / density).toInt()
val finalAdHeight = adHeight.coerceAtMost(maxHeightDp)

return AdSize(adWidth, finalAdHeight)
}
Message has been deleted

dersekranda

unread,
Apr 14, 2025, 4:04:04 AM4/14/25
to Google Mobile Ads SDK Developers
First of all, thank you for your quick response. I don't use inline adaptive ads. I display my ad in a frameLayout at the top of my application. You suggested the following function: AdSize.getInlineAdaptiveBannerAdSize( adWidth, 50).

I use AdSize(adWidth, 50). Is there a difference between them? I tested the method you suggested in the simulator. It worked without any problems. Which one should I use? Is there a difference between them?
AdSize.getInlineAdaptiveBannerAdSize( adWidth, 50) or AdSize(adWidth, 50) ?

14 Nisan 2025 Pazartesi tarihinde saat 10:19:28 UTC+3 itibarıyla Mobile Ads SDK Forum Advisor şunları yazdı:

Hi,

Thank you for contacting the Mobile Ads SDK support team.

Adaptive banners let you specify the width of an ad to determine the optimal ad size. Adaptive banners also maximize performance by optimizing the ad size for each device. This approach results in opportunities for improved performance. If you want to limit the height of the banner, use the static method AdSize.getInlineAdaptiveBannerAdSize(int width, int maxHeight) .

When implementing adaptive banners in your app, note these points:

  • 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.
  • You may need to update or create new line items to work with adaptive sizes. Learn more.

Can you check our InlineAdaptiveBannerExample as a reference for your implementation and if you have any follow up questions kindly share us with the sample project with your implementation for further investigation. 

You can provide the following details via reply privately to the author option or below link.

If the file(s) you are looking to share are less than 25mb in total you can attach them to this case on your next reply. If you are having trouble attaching your file to this case or if your file(s) are larger than 25mb, you can share your files with me by performing the following steps:

1. Navigate to

https://docs.google.com/forms/d/e/1FAIpQLSfkAiXMeYP-fw1W3Z-tT9uwmATEKO5X6S-th0gR2ezdKaaqfg/viewform?usp=pp_url&entry.400550049=Mobile+Ads+SDK&entry.460850823=500Ht00001pSkTeIAK&entry.80707362=00299639

2. Fill out all fields, and attach your file(s).

3. Please reply back on this thread when you have uploaded your file(s). Please do not share this link.

Thanks,
 
Google Logo Mobile Ads SDK Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5
[2025-04-14 07:18:41Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01pSkTe:ref" (ADR-00299639)



Message has been deleted

Mobile Ads SDK Forum Advisor

unread,
Apr 14, 2025, 4:59:01 PM4/14/25
to ebruvu...@gmail.com, google-adm...@googlegroups.com
Hi,

After looking your source code in first thread, it looks like there is no issue with that but as per Fixed size banner ads document, it has standard banner sizes list example (320x50, 320x100, 300x250, 468x60 and 728x90). 
The size of the container in which you place your ad must be at least as big as the banner. Any padding effectively decreases the size of your container. If the container cannot fit the banner ad, the ad isn't shown and the following warning is logged.:
"W/Ads: Not enough space to show ad. Needs 320x50 dp, but only has 288x495 dp."
I don't think there is any policy concern with your calculations. If just a ad size which you are requesting to load the ads and if it doesn't match the inventory then you might have to face ads not show issue. Make sure to comply with Banner ad guidance to avoid policy related issue.
As of now i would recommend to use your code in live ads loading and let us know your outcome.

Kindly get back to us if you face any issue with the ads loading along with charles logs further.

Thanks,
 
Google Logo Mobile Ads SDK Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5

[2025-04-14 20:57:54Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01pSkTe:ref" (ADR-00299639)



dersekranda

unread,
Apr 14, 2025, 5:45:05 PM4/14/25
to Google Mobile Ads SDK Developers

Ok. Thank you very much for your answer.
14 Nisan 2025 Pazartesi tarihinde saat 23:59:01 UTC+3 itibarıyla Mobile Ads SDK Forum Advisor şunları yazdı:
Reply all
Reply to author
Forward
0 new messages