android - 没有足够的空间来展示广告 (AdMob)

标签 android layout admob

我正在尝试显示 AdMob我的 Activity 中有广告,但总是出现“没有足够的空间来展示广告”的错误。

我的 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>

最佳答案

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 占用整个屏幕。

关于android - 没有足够的空间来展示广告 (AdMob),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21848532/

相关文章:

android - 有没有AudioManager.MODE_IN_COMMUNICATION蓝牙权限交互?

html - 布局对齐

android - Interstitial ads 是否比 Banner ads 帮助我们获得更多收入?

android - 将 Cordova 应用程序部署到平板电脑

android - 如何从url获取JSON数据?

java - 合并 Realm 对象和 Gson 对象

java - 重命名不同布局中的按钮问题 Android/Java

Java组件对齐到左上角

ios - 旋转 iPad 和 AdMob 不再加载,就像 iAds

java - 如何将 admob 广告添加到应用程序中?