1

使用admob网站提供的代码

这是我的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): Not enough space to show ad!想要:<480, 75>,拥有:<800, 0>

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

4

3 回答 3

6

Your grid is taking up all the space with layout_height="fill_parent".

You can use layout_weight="1" and layout_height="0dp" to tell the grid to take up all the remaining space after other views are shown.

Also are you adding the AdView programmatically? You can place it in the xml below the GridView.

Ex:

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

Make sure you replace adUnitId with your value.

于 2013-03-22T20:46:44.553 回答
2

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

于 2013-03-22T20:44:20.687 回答
0

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

于 2013-03-22T20:45:06.440 回答