2013-03-22 75 views
1

用於admob siteAndroid的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 /廣告(4244):沒有足夠的空間來顯示廣告!想要:< 480,75>,具有:< 800,0>

似乎佈局正在產生問題。請建議修復方法。非常感謝。

回答

6

您的網格佔用了所有空間layout_height =「fill_parent」

您可以使用layout_weight =「1」layout_height =「0dp」告訴電網採取了所有的剩餘空間顯示其他意見後。

您是否也以編程方式添加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設置。

+0

是的,我正在編程adtrop ...可以請你張貼片段使用XML的地方? – RDX 2013-03-22 20:50:08

+0

用示例更新。 – 2013-03-22 20:53:13

+0

非常感謝這真的很棒! b/w可以解釋ds的要求:testDevices =「TEST_EMULATOR,TEST_DEVICE_ID」。我們需要在部署應用程序之前刪除它們嗎?很多謝謝 – RDX 2013-03-22 20:55:56

2

你的gridView是貪婪的。它吃屏幕上的所有可用空間。解決方案是將頂級佈局切換爲相對佈局,並將android:layout_above「@ + id/adview」添加到GridView,並將android:layout_alignParentBottom = true添加到廣告視圖。這將迫使gridview爲廣告留下空間。

0

根據您鏈接的頁面上的Android選項卡,您的佈局中需要一個<com.google.ads.AdView>視圖,您的佈局中似乎缺少原始帖子中的視圖。

相關問題