【问题标题】:Android Admob Not enough space to show adAndroid Admob 没有足够的空间来展示广告
【发布时间】:2013-03-22 20:42:25
【问题描述】:

使用admob site中提供的代码

这是我的 xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background_img"
    android:orientation="vertical"
    android:id="@+id/atozlayout"
     >
<GridView 
    android:id="@+id/gridView1"
    android:numColumns="auto_fit"
    android:gravity="center"
    android:columnWidth="55dp"
    android:stretchMode="columnWidth"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"    
    android:horizontalSpacing="10dp"
   android:verticalSpacing="10dp"  

    >

</GridView>
</LinearLayout>

但是 logcat 显示 E/Ads(4244):没有足够的空间来展示广告!想要:,拥有:

似乎布局正在产生问题。请提出解决方法。非常感谢。

【问题讨论】:

    标签: android admob android-linearlayout space android-xml


    【解决方案1】:

    您的网格使用 layout_height="fill_parent" 占用了所有空间。

    您可以使用 layout_weight="1"layout_height="0dp" 告诉网格在显示其他视图后占用所有剩余空间。 p>

    您还以编程方式添加 AdView 吗?你可以把它放在GridView下面的xml中。

    例如:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/background_img"
        android:orientation="vertical"
        android:id="@+id/atozlayout"
         >
    <GridView 
        android:id="@+id/gridView1"
        android:numColumns="auto_fit"
        android:columnWidth="55dp"
        android:stretchMode="columnWidth"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:horizontalSpacing="10dp"
       android:verticalSpacing="10dp">
    
    </GridView>
    <com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content"
                         ads:adUnitId="MY_AD_UNIT_ID"
                         ads:adSize="BANNER"
                         ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
                         ads:loadAdOnCreate="true"/>
    
    </LinearLayout>
    

    确保将 adUnitId 替换为您的值。

    【讨论】:

    • 是的,我正在以编程方式放置 adview...你可以将 sn-p 发布到使用 xml 放置吗?
    • 非常感谢这真是太好了! b/w 你能解释一下 ds:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" 的要求吗?我们需要在部署应用程序之前删除它们吗?非常感谢
    • 是的。您可以在此处阅读有关测试的信息。 developers.google.com/mobile-ads-sdk/docs/admob/…
    • 我正在寻找一个完美的解决方案,如果用户没有连接到互联网或广告没有成功加载,它不会占据屏幕并在那里留下一个空白横幅。看起来 layout_height="wrap_content" 没有按预期工作。
    • @yancyn 发生这种情况时,您应该手动隐藏广告视图。
    【解决方案2】:

    您的 gridView 很贪心。它吃掉了屏幕上的所有可用空间。解决方案是将顶层布局切换为Relative布局,并将 android:layout_above"@+id/adview" 添加到 GridView 和 android:layout_alignParentBottom=true 到广告视图。这将强制 gridview 在其下方为广告留出空间。

    【讨论】:

      【解决方案3】:

      根据您链接的页面上的 Android 选项卡,您的布局中需要一个 &lt;com.google.ads.AdView&gt; 视图,您的原始帖子中似乎缺少该视图。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-02-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多