Подтвердить что ты не робот

Недостаточно места для показа рекламы (AdMob)

Я пытаюсь показать AdMob объявления в своей деятельности, но всегда дает ошибку, что "недостаточно места для показа рекламы".

Мой XML файл:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <com.google.ads.AdView
        android:id="@+id/adMobadView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        ads:adSize="BANNER"
        ads:adUnitId="@string/admobid"
        android:layout_alignParentBottom="true"
        android:gravity="bottom|center_horizontal"
        ads:loadAdOnCreate="true" />
</RelativeLayout>

Мой файл Java:

    AdView ad=(AdView)findViewById(R.id.adMobadView);

    AdRequest re = new AdRequest();
    re.setTesting(true);
    re.setGender(AdRequest.Gender.FEMALE);
    ad.loadAd(re);

LogCat:

   02-18 14:16:17.869: W/webcore(813): Can't get the viewWidth after the first layout
   02-18 14:16:17.979: I/Ads(813): onReceiveAd()
   02-18 14:16:17.979: W/Ads(813): Not enough space to show ad! Wants: <320, 50>, Has: <288, 430>
4b9b3361

Ответ 1

Левое и правое дополнение вашего RelativeLayout потребляет пространство, необходимое вашему AdView.

Измените конфигурацию RelativeLayout на:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 ...
 android:paddingLeft="0dp"
 android:paddingRight="0dp"
 ...
>

Вероятно, вы также захотите изменить конфигурацию AdView на:

<com.google.ads.AdView
        android:id="@+id/adMobadView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ...
        />

так как вы не хотите, чтобы ваш AdView потреблял весь экран.

Ответ 2

Проверьте размеры экрана и прокладки и посмотрите, действительно ли он подходит.

Кроме того, попробуйте изменить Adview на это:

    <com.google.ads.AdView
        android:id="@+id/adMobadView"
        android:layout_width="320dp"
        android:layout_height="50dp"
        ads:adSize="BANNER"
        ads:adUnitId="@string/admobid"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:loadAdOnCreate="true" />

Ответ 3

to show ads inside relative layout you can follow this design

<RelativeLayout
        android:id="@+id/relativeLayoutpopular"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_above="@+id/bottomBar"
        android:layout_below="@+id/relativeLayoutadd"
        android:layout_marginTop="5dp"
        >
            <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:paddingTop="3dp">
         <com.google.ads.AdView
             xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
             android:id="@+id/adView"
             android:layout_width="fill_parent"
            android:layout_weight="0.9"
            android:layout_height="wrap_content"
            ads:adSize="SMART_BANNER"
            android:background="#2d2f2f"
            ads:adUnitId="admobId" />
        </LinearLayout>
    </RelativeLayout>

Ответ 4

У меня была такая же проблема с NativeExpressAdView. Если вы добавите дополнение или маржу к своему макету, я думаю, что это не очень хорошая идея, чтобы исправить ширину размера объявления. Я предлагаю делать программно

  • Первый шаг: получить размер dp экрана witdh

    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); //float dpHeight = displayMetrics.heightPixels / displayMetrics.density; dpWidth = displayMetrics.widthPixels / displayMetrics.density;

2. Второй шаг:

mAdView.setAdSize(new AdSize((int) dpWidth, 150));

Ответ 5

Просто установите поля 0dp в res- > values- > dimens.xml

<dimen name="activity_horizontal_margin">0dp</dimen>
<dimen name="activity_vertical_margin">0dp</dimen>