I'm trying to set AdMob banner ad to match it's parent width.
I tried as sample:
<com.google.ads.AdView
android:id="@+id/ad"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
ads:adSize="BANNER"
ads:adUnitId="app-pub-id"
ads:loadAdOnCreate="true"/>
And got:
I also tried with:
ads:adSize="SMART_BANNER"
In the IDE xml preview, I got:
But in fact the ad didn't match his parent width.
Anyone?
The right way to set AdMob banner to match his parent by XML is:
<com.google.ads.AdView
android:id="@+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub_id"
ads:loadAdOnCreate="true"/>
In addition, as mention before, the ability to match parent depends on the advertiser.
If the advertiser supplied the relevant resources, the ad will stretch to match his parent.
For example full size ad on Nexus 4:
adView.setAdSize(AdSize.SMART_BANNER);
If you look at the list of Admob Banner Sizes you'll see that since you are setting a height of 50 dp, you'll be getting a 320 dp x 50 dp banner. Depending on which device you are looking at won't be able to fill the width of the ad slot (e.g. a Nexus 7). The behavior of AdMob Smart Banners is different in that it is a bit more responsive to the different Android configurations by adjusting it size.
The limitations in ad size allow for advertisers to allow the same ad creative to run on multiple platforms without change.
Check the AdMob Documentation on Banners for Android for their suggested layout XML.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With