java - AdMob 横幅 : Not enough space to show ad

标签 java android xml

我想在我的应用程序中显示 Google 的横幅。我有这个布局(activity_main):

<?xml version="1.0" encoding="utf-8"?>

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"      
        xmlns:ads="http://schemas.android.com/apk/res-auto"     
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar"/>      

    <FrameLayout 
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>      

    <RelativeLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="@string/id">
    </com.google.android.gms.ads.AdView>

    </RelativeLayout>
    </LinearLayout>

当我运行我的应用程序时,我在 logcat 中看到这个错误:

Not enough space to show ad. Needs 320x50 dp, but only has 360x0 dp.

如何修复它并显示横幅?提前致谢。

最佳答案

你的 FrameLayoutRelativeLayout width 应该是 wrap_content,或者 0dp 和 weight 如果您愿意,两者或其他比例都等于 1,出现此问题的原因是您的 FrameLayout witdh 设置为 match_parent

如果你想使用 weight 你应该改变你的 LinearLayout 方向到 horizo​​ntal

关于java - AdMob 横幅 : Not enough space to show ad,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30693731/

相关文章:

java - 解析 findInBackground 不添加到全局数组列表?

javascript - 无法返回 xmlhttp.responseText?

android - 我们可以在不影响设备音量的情况下将Android应用的音量设置为相对于设备的音量吗?

java - 如何在 Android 上安全地存储存储敏感日期?

android动画切换UI和active类

c#(更具体地说是 xna)如何通过 http 请求 xml 文件?不需要支持 xbox

java - 在任何平台上从代码启动 Jar 文件

java - 如何拥有带有左右箭头的 Java Spinner?

java - 如何找到错误 TCP 连接的原因

android - 在 Android 上清除剪贴板