0

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?

Hippogriff
  • 295
  • 1
  • 4
  • 18
  • I would add that an app with a *single* layout - handling *all* resolutions and *both* orientations - shows the ad fine on *all* devices. So, the issue I have *only* seems to arise when I'm specifically using layout that's `layout-hdpi`. – Hippogriff Feb 28 '14 at 14:16

1 Answers1

2

I eventually managed to do this by creating a top-level LinearLayout with 2 RelativeLayout items included inside. One RelativeLayout, for the UI components, can keep its padding, as suggested by the Android design guidelines (and what looks nice). The other RelativeLayout has no padding so the ad fits inside (it previously complaining it wanted 480 pixels of screen space).

The UI RelativeLayout has a android:layout_weight="1" and the ad RelativeLayout has a android:layout_weight="7.2" - which seems to work for devices with screens of 480 by 800 (hdpi).

Feels like a bit of a hack, to me, but it works.

Hippogriff
  • 295
  • 1
  • 4
  • 18