问题
It is not a new error but none of the online answers look to me more approprite, Kindly help me in this problem. I have incorporated Admob in my application. It is working on some Screens perfectly but on other it is not working. When I looked on the log it says.
Not enough space to show ad! Wants: <480, 75>, Has: <464, 762>
I want to know that is there an easy way to display ads on all screens sizes and avoid such errors.
My XML code is as follows.
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ADMOB_PUBLISHER_ID"
ads:loadAdOnCreate="true" />
I have provided permissions of Internet and Access network state.
回答1:
Any chance you have an 8dp margin/padding on each side of your main layout? The AdView needs the entire width of the screen (in portrait) to be able to display the ad, but it only has 464dp of width space.
回答2:
try:
android:layout_width="480dp"
android:layout_height="wrap_content"
or
android:layout_width="480dp"
android:layout_height="75dp"
回答3:
the problem is on the line
android:layout_width="fill_parent"
the layout container is not big enought to contain the adview. Try to set it to:
android:layout_width="320dp"
, this will ask an ad with a different (smaller) size.
回答4:
here i give a sample example code. you can follow.
step 1:
design your activity layout like this
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent">
<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_height="wrap_content"
ads:adSize="SMART_BANNER"
android:background="#2d2f2f"
ads:adUnitId="ADMOB_PUBLISHER_ID" />
</LinearLayout>
step 2:
follow this code in activity
final AdView adview=(AdView)findViewById(R.id.adView);
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
AdRequest re = new AdRequest();
//re.setTesting(true);
adview.loadAd(re);
}
});
step 3:
add permission in application manifest
<uses-sdk
android:minSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
also add admob activity in manifest
<activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
来源:https://stackoverflow.com/questions/9384025/not-enough-space-to-display-admob-ad-error