我是 Android 新手。 我通过在 main.xml 中进行以下更改,在我的 Android 应用程序中添加了 AdMob:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="match_parent"
ads:adSize="BANNER"
ads:adUnitId="XXXXXXXXX"
ads:loadAdOnCreate="true" />
</LinearLayout>
</TabHost>
我的项目运行成功,没有错误,但我没有收到广告。
WARN/Ads(3805): Not enough space to show ad! Wants: <320, 50>, Has: <320, 0>.
最佳答案
这意味着您的布局中没有显示广告的空间。将其更改为 RelativeLayout 并对齐父底部。
<RelativeLayout
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@android:id/tabs"/>
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="XXXXXXXXX"
ads:loadAdOnCreate="true"
/>
</RelativeLayout>
关于android - AdMob "Not enough space to show ad"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13491560/