Not enough space to show ad (AdMob)

后端 未结 5 2062
挽巷
挽巷 2020-11-30 13:45

I am trying to show AdMob ads in my activity, but it is always giving error that \"not enough space to show ad\".

My XML file is:



        
相关标签:
5条回答
  • 2020-11-30 14:14

    i had the same problem with NativeExpressAdView. If you add padding or margin to your layout, I think, it's not a good idea to fix the ad's size width. I sugger to do in programmatically

    1. First step : get the dp size of screen witdh

      DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); //float dpHeight = displayMetrics.heightPixels / displayMetrics.density; dpWidth = displayMetrics.widthPixels / displayMetrics.density;

    2. Second step:

    mAdView.setAdSize(new AdSize((int) dpWidth, 150));

    0 讨论(0)
  • 2020-11-30 14:22
    to show ads inside relative layout you can follow this design
    
    <RelativeLayout
            android:id="@+id/relativeLayoutpopular"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_above="@+id/bottomBar"
            android:layout_below="@+id/relativeLayoutadd"
            android:layout_marginTop="5dp"
            >
                <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:paddingTop="3dp">
             <com.google.ads.AdView
                 xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
                 android:id="@+id/adView"
                 android:layout_width="fill_parent"
                android:layout_weight="0.9"
                android:layout_height="wrap_content"
                ads:adSize="SMART_BANNER"
                android:background="#2d2f2f"
                ads:adUnitId="admobId" />
            </LinearLayout>
        </RelativeLayout>
    
    0 讨论(0)
  • 2020-11-30 14:28

    The left and right padding of your RelativeLayout is consuming space required by your AdView.

    Change RelativeLayout config to :

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     ...
     android:paddingLeft="0dp"
     android:paddingRight="0dp"
     ...
    >
    

    You probably also want to change your AdView config to:

    <com.google.ads.AdView
            android:id="@+id/adMobadView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            ...
            />
    

    as you don't really want your AdView to consume the entire screen.

    0 讨论(0)
  • 2020-11-30 14:36

    Simply set the margins to 0dp in res->values->dimens.xml

    <dimen name="activity_horizontal_margin">0dp</dimen>
    <dimen name="activity_vertical_margin">0dp</dimen>
    
    0 讨论(0)
  • 2020-11-30 14:41

    Check the dimensions of the screen and the paddings, and see if it actualy fits.

    Also, try to change the Adview to this:

        <com.google.ads.AdView
            android:id="@+id/adMobadView"
            android:layout_width="320dp"
            android:layout_height="50dp"
            ads:adSize="BANNER"
            ads:adUnitId="@string/admobid"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            ads:loadAdOnCreate="true" />
    
    0 讨论(0)
提交回复
热议问题