AdMob Ошибка "Недостаточно места для показа рекламы"
Я новичок в Android. Я добавил AdMob в свое приложение для Android, внеся следующие изменения в main.xml:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="match_parent"
ads:adSize="BANNER"
ads:adUnitId="XXXXXXXXX"
ads:loadAdOnCreate="true" />
</LinearLayout>
</TabHost>
Мой проект успешно работает без ошибок, но я не получаю объявление.
WARN/Ads(3805): Not enough space to show ad! Wants: <320, 50>, Has: <320, 0>.
2 ответа
Решение
Это означает, что в вашем макете нет места для показа рекламы. Измените его на RelativeLayout и выровняйте родительское основание.
<RelativeLayout
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@android:id/tabs"/>
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="XXXXXXXXX"
ads:loadAdOnCreate="true"
/>
</RelativeLayout>
Это вызывает проблему.
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
Ваш FrameLayout занимает всю высоту в представлении. Так что даже если вы пишете AdView ниже FrameLayout, он получает 0 высоту.
Concider, включая AdMob, во время выполнения внутри вашего FrameLayout.