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)を示しています:広告を表示するのに十分なスペースがありません!欲しいもの:<480、75>、持っているもの:<800、0>

レイアウトが問題を引き起こしているようです。修正方法を提案してください。どうもありがとう。

4

3 に答える 3

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を自分の値に置き換えてください。

于 2013-03-22T20:46:44.553 に答える
2

あなたのgridViewは貪欲です。画面上の利用可能なすべてのスペースを消費します。解決策は、トップレベルのレイアウトを相対レイアウトに切り替え、android:layout_above "@ + id / adview"をGridViewに追加し、android:layout_alignParentBottom=trueを広告ビューに追加することです。これにより、グリッドビューはその下に広告用のスペースを残します。

于 2013-03-22T20:44:20.687 に答える
0

リンクしたページの[Android]タブによると、<com.google.ads.AdView>元の投稿から欠落しているように見えるレイアウトのビューが必要です。

于 2013-03-22T20:45:06.440 に答える