【问题标题】:Admob Error: Not enough space to show ad. Needs 320x50 dp, but only has 309x0 dpAdmob 错误:没有足够的空间来展示广告。需要 320x50 dp,但只有 309x0 dp
【发布时间】:2019-04-11 20:20:47
【问题描述】:

我正在尝试在我的片段布局中投放智能横幅广告,但我不断得到的是“没有足够的空间来展示广告。需要 320x50 dp,但只有 309x0 dp”。

这是我的片段布局。

<android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:scrollbars="vertical"
    android:fillViewport="true"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/details_layout"
    android:background="@android:color/white"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.app.bookng.DetailsFragment">

    <RelativeLayout

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/details_relat"
        android:padding="5dp">

        <com.google.android.gms.ads.AdView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"
            android:id="@+id/banner_id"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="XXXXXXXXXXXXXXXXXXXXXXXXXXXX"/>

        <ProgressBar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:indeterminate="true"
            android:id="@+id/progress_circle"
            android:visibility="gone"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_centerInParent="true"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:hint="@string/title"
            android:id="@+id/dbook_title"
            android:visibility="gone"
            android:layout_margin="5dp"
            android:textStyle="bold"/>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="30dp"
            android:layout_marginTop="20dp"
            android:layout_marginRight="10dp"
            android:layout_marginLeft="10dp"
            android:layout_below="@+id/dbook_title"
            android:id="@+id/rootauthor_date"
            android:gravity="center_vertical">

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginLeft="10dp"
                android:visibility="gone"
                android:background="#d1d1d1"
                android:layout_alignParentTop="true"
                android:id="@+id/dviewtop"
                android:layout_marginTop="15dp"
                android:layout_toRightOf="@+id/author_img"/>


            <com.app.bookng.CircularNetworkImageView
                android:layout_width="90dp"
                android:layout_height="90dp"
                android:visibility="gone"
                android:padding="3dp"
                android:layout_alignParentLeft="true"
                android:id="@+id/author_img"
                android:scaleType="centerCrop"
                android:background="@drawable/round_button"/>

            <TextView
                android:layout_width="wrap_content"
                android:visibility="gone"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/author_img"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="10dp"
                android:layout_centerVertical="true"
                android:layout_below="@+id/dviewtop"
                android:id="@+id/author_date"/>



            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginLeft="10dp"
                android:visibility="gone"
                android:background="#d1d1d1"
                android:id="@+id/dviewbottom"
                android:layout_marginTop="10dp"
                android:layout_below="@+id/author_date"
                android:layout_toRightOf="@+id/author_img"/>
        </RelativeLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/rootauthor_date"
            android:hint="@string/main_body"
            android:textColorLink="@color/textlink"
            android:visibility="gone"
            android:id="@+id/dbook_content"
            android:layout_margin="5dp"/>


        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/gad_title"
            android:textStyle="bold"
            android:visibility="gone"
            android:textAppearance="?android:attr/textAppearanceMedium"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/gad_pic"
            android:visibility="gone"
            android:layout_below="@+id/gad_title"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/gad_feat"
            android:visibility="gone"
            android:layout_below="@+id/gad_pic"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="gone"
            android:layout_below="@+id/gad_feat"
            android:id="@+id/gad_content"/>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:visibility="gone"
            android:background="#d1d1d1"
            android:id="@+id/viewtop_share"
            android:layout_below="@+id/dbook_content"/>


        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/viewtop_share"
            android:id="@+id/comment_container"/>

    </RelativeLayout>


</android.support.v4.widget.NestedScrollView>

这是活动布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

     //Container for toolbar    
    <include layout="@layout/post_toolbar"/>

    //Container for fragment    
    <include layout="@layout/share_layout"/>


</FrameLayout>

我真的不明白为什么高度是 0dp。请问您能帮帮我吗?

【问题讨论】:

  • 尝试从您的相关布局中删除android:padding="5dp"
  • @Shubhank 令人惊讶地修复了它。请输入它作为答案,以便我接受。

标签: android admob


【解决方案1】:

根据 Admob 文档/指南

广告视图必须是设备的全宽。 由于您将 padding 提供给您的布局,因此它失败了,因为它无法填充布局的整个宽度。

您只需删除 RelativeLayout 中的填充即可解决此问题

【讨论】:

【解决方案2】:

将 SMART_BANNER 替换为 BANNER。再轻松不过了。

【讨论】:

    【解决方案3】:

    当 adSize 是 SMART_BANNER 将其替换为 LARGE_BANNER 或 BANNER 解决了问题时,我遇到了同样的问题。 SMART_BANNER 广告以设备宽度显示。如果您的广告的版面宽度小于设备宽度,则会导致错误“空间不足,无法展示广告”

    【讨论】:

      【解决方案4】:

      把它放在你的 android manifest.xml 中

      <activity android:windowSoftInputMode="adjustPan"> </activity>
      

      【讨论】:

        猜你喜欢
        • 2017-07-04
        • 2016-03-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多