简体   繁体   中英

AdMob Banner: Not enough space to show ad

i'm tring to show a Google's banner inside my application. I've this layout (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>

When i run my app i see in the logcat this error:

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

How can i fix it and show the banner? Thanks in advance.

Your FrameLayout and RelativeLayout width should be wrap_content , or 0dp and weight equals to 1 for both or other proportions if you want, the reason for this issue is that your FrameLayout witdh is set to match_parent

And if you want to use weight you should change your LinearLayout orientation to horizontal

You can add android:windowSoftInputMode="adjustPan|adjustResize" to the activity in your manifest file.

Hope this will help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM