AdMob广告未显示。没有足够的空间来展示广告

时间:2013-08-17 12:13:53

标签: android android-layout admob

我试图将AdMob广告添加到我的应用中。 我想在ListView下添加一个横幅广告,但没有展示广告,并且阅读日志看起来没有足够的空间让横幅显示出来。

  

08-17 20:11:00.976:E / Ads(7586):没有足够的空间来展示广告!想要:< 320,50>,具有:< 992,0>

最后这是我的整个布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/current_path_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/current_path"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/list_of_files"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ListView>
    </LinearLayout>

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

        <com.google.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adSize="BANNER"
            ads:adUnitId="XXXXXXXXXXXXX"
            ads:loadAdOnCreate="true"
            ads:testDevices="XXXXXXXXXXXXX" />
    </LinearLayout>

</LinearLayout>

2 个答案:

答案 0 :(得分:4)

只需在列表视图中定义权重....

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


        <TextView
            android:id="@+id/current_path_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Ding Chak"
            android:textAppearance="?android:attr/textAppearanceLarge" />


        <ListView
            android:id="@+id/list_of_files"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:layout_weight="1">
        </ListView>

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

        <com.google.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adSize="BANNER"
            ads:adUnitId="XXXXXXXXXXXXX"
            ads:loadAdOnCreate="true"
            ads:testDevices="XXXXXXXXXXXXX" />
    </LinearLayout>

</LinearLayout>

答案 1 :(得分:0)

只需在res-&gt; values-&gt; dimens.xml

中将边距设置为0dp
<dimen name="activity_horizontal_margin">0dp</dimen>
<dimen name="activity_vertical_margin">0dp</dimen>