I've created a additional portrait layout for devices like Samsung S3 Mini and Google Nexus S - which are 480 pixels wide in portrait.
To add this cloned layout, I used Android Studio to Create Other... then selected Density and chose High Density to provide me with a copy of the layout inside the new folder res/layout-hdpi
- the layout works mostly fine in the Emulator when I use an AVD created for the 480 x 800 screen size (things appear and are where you expect them to be).
However, my AdMob ad, that works fine in the the other layouts - e.g. layout-sw360dp-port
and layout-sw600dp-port
- is not shown. LogCat states Not enough space to show ad. Needs 480x75, but only has 432x570
.
This partially makes sense to me - as the RelativeLayout
that the com.google.android.gms.ads.AdView
resides in has both android:paddingLeft="@dimen/activity_horizontal_margin"
and android:paddingRight="@dimen/activity_horizontal_margin"
set, as per Android design guidelines - which must be about 24 pixels each.
So, it makes sense that the horizontal space available is not 480 (the width of the device) but, rather, 432 (the width of the RelativeLayout
after padding).
However, why does the ad thinks it needs all that horizontal space?
The XML for the ad looks like this:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="@string/adUNITID"
ads:adSize="BANNER"
android:id="@+id/adView"
android:layout_alignParentStart="false"
android:layout_alignParentEnd="false"
android:layout_alignParentBottom="true" />
The documentation implies that an ad of type BANNER
should require "320x50 density-independent pixels", I'm confused why it says 480 is required in LogCat.
As it did not show the ad with BANNER
, I then tried SMART_BANNER
(which is a "dynamically sized banner that is full-width") and that also failed to show (with the same message in the LogCat).
Am I missing something rather obvious here? I'm stumped as to why a normal BANNER
-sized ad (that I think should easily fit into the space available) is saying it cannot display, on a device like the Samsung S3 Mini or Google Nexus S. Do I have to remove that padding which the RelativeLayout
has? Is that a good idea?