Tugees Tugees - 4 months ago 59
Android Question

Admob - Not enough space to show ad wants

I have integrated Admob which is serving DFP ads. Here is the XML code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/headerAdLayout"
android:paddingLeft="0dp"
android:paddingRight="0dp">
<com.google.android.gms.ads.doubleclick.PublisherAdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
ads:adUnitId="/4359979/Top"
ads:adSize="BANNER"
>

</com.google.android.gms.ads.doubleclick.PublisherAdView>
</LinearLayout>


I then explicitly set the ad sizes prior to loading the ads to try to ensure that there is enough space. I have additionally ensured that there is no padding both to the left and the right

PublisherAdView mAdView = (PublisherAdView) header.findViewById(R.id.adView);
mAdView.setMinimumWidth(720);
mAdView.setMinimumHeight(404);
mAdView.setAdSizes(new AdSize(720, 404));
PublisherAdRequest adRequest = new PublisherAdRequest.Builder().build();
mAdView.loadAd(adRequest);


However I still get this message in Logcat:

Not enough space to show ad. Needs 720x404 dp, but only has 533x404 dp.


My screen width is being reported as 800 using the following code. (am running in landscape mode on a Samsung S4 mini device)

WindowManager wm = (WindowManager) activity.getSystemService(activity.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
int width = display.getWidth();


Where am I getting it wrong?

Answer

Not enough space to show ad. Needs 720x404 dp, but only has 533x404 dp.

but your device is reporting 800 pixels, pixels is not the same as dp so based on the Screen density of your device

  • .75 on ldpi (120 dpi)
  • 1.0 on mdpi (160 dpi; baseline)
  • 1.5 on hdpi (240 dpi)
  • 2.0 on xhdpi (320 dpi)
  • 3.0 on xxhdpi (480 dpi)
  • 4.0 on xxxhdpi (640 dpi)

you will calculate how many dp is really reporting your device, for example with a Screen Density of 2.0:

dp = px / (dpi / 160) = 800/(320 / 160) = 400 dp (404dp)
Comments