使用中提供的代码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):没有足够的空间来显示广告!想要:,拥有:
似乎布局正在产生问题。请建议修复方法。非常感谢。
你的网格占据了所有的空间布局高度=“填充父级”.
您可以使用布局权重=“1” and 布局高度=“0dp”告诉网格在显示其他视图后占用所有剩余空间。
您还以编程方式添加 AdView 吗?您可以将其放置在 GridView 下面的 xml 中。
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>
确保将 adUnitId 替换为您的值。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)