Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Banner Ad Full width Issue

176 views
Skip to first unread message

Abhishek Pundir

unread,
Feb 22, 2025, 7:07:36 AMFeb 22
to Google Mobile Ads SDK Developers
I was trying to implement a view in which I want the Ad to take the full width of the available device but the height remains constant (i.e. 60dp). To achieve this, I used
 AdSize.getInlineAdaptiveBannerAdSize(width, 60).

But it is not giving me the correct ad size units as shown in the attached screenshots. The width of the ad unit received is mostly less than that of the screen width.
 Does anyone know how I can achieve the behaviour I am expecting? (i.e. an ad of full device width and height of 60dp) 


Screenshot 2025-02-17 at 12.14.55 AM.png
Screenshot 2025-02-17 at 12.15.11 AM.png

Mobile Ads SDK Forum Advisor

unread,
Feb 24, 2025, 2:10:15 AMFeb 24
to abhishek...@gmail.com, google-adm...@googlegroups.com

Hi Abhishek,

Thank you for contacting the Mobile Ads SDK Support team.

Unlike anchored adaptive banners, inline adapter banners load using an inline adaptive banner size. To create an inline adaptive ad size, complete the following:

  1. Get the width of the device in use, or set your own width if you don't want to use the full width of the screen.
  2. Use the appropriate static methods on the ad size class, such as AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(Context context, int width) to get an inline adaptive ad size object for the chosen orientation.
  3. If you want to limit the height of the banner, use the static method AdSize.getInlineAdaptiveBannerAdSize(int width, int maxHeight) .

Could you please confirm if the issue occurs in our Google sample application after implementing the changes based on your requirements? If so, kindly share your sample application where the issue can be reproduced.

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=5004Q00002vH3FmQAK&entry.80707362=00289289

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-02-24 07:09:17Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02vH3Fm:ref" (ADR-00289289)



Abhishek Pundir

unread,
Feb 24, 2025, 3:05:39 AMFeb 24
to Google Mobile Ads SDK Developers
Hi Team, 
Thanks for looking into this. but as mentioned in the problem statement as well, i am getting the device width (and as i printed it in the logs, this is coming out to be correct) and then using the API call AdSize.getInlineAdaptiveBannerAdSize(width, 60). as i want to limit the ad height to 60 dp. 
But still using this implementation i am not getting the correct size ads and getting ones that are smaller than the mentioned size (as shown in the screenshots attached). 
Screenshot 2025-02-17 at 12.15.11 AM.png
Screenshot 2025-02-17 at 12.14.55 AM.png

Abhishek Pundir

unread,
Feb 24, 2025, 4:26:31 AMFeb 24
to Google Mobile Ads SDK Developers
Just to clarify further, its not that i am only getting ad sizes smaller than the ones requested. 
Sometimes i even get the correct sizes of the ads as well. 
Sharing the screenshots of the ads received even on subsequent launches in the app. 
Screenshot 2025-02-17 at 12.15.11 AM.png
Screenshot 2025-02-17 at 12.14.55 AM.png
Screenshot 2025-02-24 at 2.54.06 PM.png
Screenshot 2025-02-24 at 2.53.55 PM.png
Screenshot 2025-02-24 at 2.53.46 PM.png

Mobile Ads SDK Forum Advisor

unread,
Feb 24, 2025, 10:04:30 AMFeb 24
to abhishek...@gmail.com, google-adm...@googlegroups.com

Hi Abhishek,

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. Also refer to Serve reservations in adaptive banners help center article for more information. If this doesn’t help kindly provide us with the sample project as requested earlier. 


Thanks,
 
Google Logo Mobile Ads SDK Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5

[2025-02-24 15:03:32Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02vH3Fm:ref" (ADR-00289289)



Abhishek Pundir

unread,
Feb 25, 2025, 2:36:20 AMFeb 25
to Google Mobile Ads SDK Developers
Hi Team, 

I am already using the full device width and sending that to the function in adView.setAdSize(getAdSize(activity)) in order to set the ad size in the adView. 


fun getAdSize(activity: Activity): AdSize
{
val displayMetrics: DisplayMetrics = activity.resources.displayMetrics
var adWidthPixels = displayMetrics.widthPixels

if (VERSION.SDK_INT >= VERSION_CODES.R)
{
val windowMetrics: WindowMetrics = activity.windowManager.currentWindowMetrics
adWidthPixels = windowMetrics.bounds.width()
}

val density = displayMetrics.density
val adMargin = 32 * density

val adWidth = ((adWidthPixels - adMargin) / density).roundToInt()

return AdSize.getInlineAdaptiveBannerAdSize(adWidth, 60)
}

Mobile Ads SDK Forum Advisor

unread,
Feb 25, 2025, 8:08:55 AMFeb 25
to abhishek...@gmail.com, google-adm...@googlegroups.com

Hi Abhishek,

In the provided function I observed that The width issue is caused by where you calculate the margin. To resolve this, kindly use below code to calculate the full screen ad size and verify the results.

 fun getAdSize(activity: Activity): AdSize
  {
    val displayMetrics: DisplayMetrics = activity.resources.displayMetrics
    var adWidthPixels = displayMetrics.widthPixels
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
    {
      val windowMetrics: WindowMetrics = activity.windowManager.currentWindowMetrics
      adWidthPixels = windowMetrics.bounds.width()
    }
    val density = displayMetrics.density
   
    val adWidth = ((adWidthPixels - adMargin) / density).roundToInt()
    return AdSize.getInlineAdaptiveBannerAdSize(adWidth, 60)
  }
Thanks,
 
Google Logo Mobile Ads SDK Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5

[2025-02-25 13:07:55Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02vH3Fm:ref" (ADR-00289289)



Abhishek Pundir

unread,
Feb 25, 2025, 1:41:41 PMFeb 25
to Google Mobile Ads SDK Developers
Hi Team, 
Thanks for looking into this, but the code snippet that you shared and the one which i shared has the only difference of adMargin variable being removed and i can't see any other change. 
(Since you removed adMargin variable from your code snippet, your code won't even compile as you have used adMargin later while calculating the adWidth). 

Also i need to subtract the adMargin while calculating the adWidth as i have used 32dp of margin in the ad container view which i used in the UI. 

Mobile Ads SDK Forum Advisor

unread,
Feb 25, 2025, 6:34:54 PMFeb 25
to abhishek...@gmail.com, google-adm...@googlegroups.com

Hi,

Could you kindly provide the sample project privately for further investigation: 

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 via reply to author option 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=5004Q00002vH3FmQAK&entry.80707362=00289289

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-02-25 23:34:02Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02vH3Fm:ref" (ADR-00289289)



Abhishek Pundir

unread,
Feb 26, 2025, 12:59:56 PMFeb 26
to Google Mobile Ads SDK Developers
Hi Team, 
I am trying this out in my production app, so i would not be able to share the source code. 
Is there any other way which might help you look at the issue. 

Mobile Ads SDK Forum Advisor

unread,
Feb 26, 2025, 5:17:46 PMFeb 26
to abhishek...@gmail.com, google-adm...@googlegroups.com

Hi,

Thank you for getting back to us.

I'm afraid that we'll need detailed debug information from a device where it's observed in order to actually make any progress in diagnosing this. The only way for us to investigate further is by creating a project where the issue is reproducible.

Could you kindly provide the sample project or Charles log privately for further investigation:

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 to us via reply to author option or by performing the following steps:

3. Please reply back to 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-02-26 22:16:57Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02vH3Fm:ref" (ADR-00289289)



zhou

unread,
Apr 24, 2025, 11:01:55 AMApr 24
to Google Mobile Ads SDK Developers
I also have a similar question.
屏幕截图 2025-04-24 111350.png

After checking with the tool layout inspector, it was found that:

  1. Sometimes the width of the banner ad view (adView) being displayed is smaller than the screen width.

  2. Sometimes the adView width is normal, but the content inside it is smaller than the screen width and is not centered.

The Admob version is 23.2.0

Here is my key code:
DisplayMetrics outMetrics = Resources.getSystem().getDisplayMetrics();
float widthPixels = outMetrics.widthPixels;
float density = outMetrics.density;
int adWidth = (int) (widthPixels / density);
adView.setAdSize(AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(ConfigApplication.getContext(), adWidth))

Mobile Ads SDK Forum Advisor

unread,
Apr 24, 2025, 3:53:49 PMApr 24
to zhou97...@gmail.com, google-adm...@googlegroups.com

Hi,

Thank you for contacting the Mobile Ads SDK Support team.

I ran the Google Sample Application ads that are showing correctly.

Could you please confirm if the issue occurs in our Google sample application after implementing the changes based on your requirements? If so, kindly share your sample application where the issue can be reproduced.

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:

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-24 19:52:45Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02vH3Fm:ref" (ADR-00289289)



zhou

unread,
Apr 25, 2025, 11:34:58 AMApr 25
to Google Mobile Ads SDK Developers
  It only occurs occasionally in the production environment and cannot be reproduced with test ads. We also cannot confirm whether this issue is caused by a specific mediation( Of course, this doesn't seem to occur in just one mediation). This problem has a significant impact on our app's UI. As shown in the key code I provided, what I expect is a banner ad that matches the full screen width, or is centered if it does not. Please tell me what I should do.  
屏幕截图 2025-04-24 175330.png

Mobile Ads SDK Forum Advisor

unread,
Apr 25, 2025, 4:51:07 PMApr 25
to zhou97...@gmail.com, google-adm...@googlegroups.com

Hi,
We kindly request your support in providing the necessary information like sample project and charles logs.This information will help us conduct a thorough investigation and check with the wider team if required.Without them, we will not be able to proceed further in identifying the root cause of the issue.


kindly provide the sample project or Charles log privately for further investigation:

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=5004Q00002vH3FmQAK&entry.80707362=00289289

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-25 20:50:06Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02vH3Fm:ref" (ADR-00289289)



Reply all
Reply to author
Forward
0 new messages