Anton Derevyanko
Anton Derevyanko

Reputation: 3445

Empty space after AdMob disappear

I have layout structure:

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" >
  <com.google.ads.AdView 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   ads:adSize="BANNER"
  />
    
  <LinearLayout style="@style/TitleBar"
   android:layout_width="fill_parent"
   android:layout_height="45dip"
    // title bar
  </LinearLayout>
  
<RelativeLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  // main layout with all needed elements and background!" >
  
</RelativeLayout>
</LinearLayout>

Everything look fine, until my AdMob disappered. Then I can see empty black region with admob size.

UPDATE: my screen shot: enter image description here

normally I cas see here ad block, but when I get onFailedToReceiveAd(Ad request successful, but no ad returned due to lack of ad inventory.) ad disappers and my layout not fill all screen.

Upvotes: 9

Views: 5680

Answers (4)

Smugrik
Smugrik

Reputation: 850

What you describe looks weird... The reason I believed caused an ad to disappear was in case an ad is refreshed and then no ad is served due to lack of ad on AdMob side. But from my own test, once an ad is loaded, if a subsequent ad refresh fails, the previous ad stays displayed, I haven't seen ads 'disappear'.

Maybe you could look at logcat and see if you get any errors there.

Here is some code I used to test Ad Request delivery/failure on my own app. In case the blanks appears after an Ad fails loading, I suppose you could put some code inside the onFailedToReceiveAd to resize the AdView

AdView av = (AdView)findViewById(R.id.adView);

        // Set AdListener
        av.setAdListener(new AdListener() {
            AdView av = (AdView)findViewById(R.id.adView);
            @Override
            public void onFailedToReceiveAd(Ad ad, ErrorCode error) {
                System.err.println("Ad failed: " + ad.toString() + error.toString());
                av.setVisibility(AdView.GONE);//By setting visibility to GONE, you hide the AdView, but the AdView won't refresh automaticaly anymore.

            }

            @Override
            public void onReceiveAd(Ad ad) {
                System.out.println("Ad received: " + ad.toString());
                av.setVisibility(AdView.VISIBLE);
            }
        });

        // Create an ad request.
        AdRequest adRequest = new AdRequest();

        // Start loading the ad in the background.
        av.loadAd(adRequest);

Upvotes: 5

Chris Lucian
Chris Lucian

Reputation: 1013

Use the Set Visibility function to remove it from the layout.

SetVisibility()

Check this post also on hiding the AdView

Upvotes: 1

Smugrik
Smugrik

Reputation: 850

Another way to look at this would be to set up your own 'house ad' in AdMob to target your app. Then when AdMob doesn't have an ad to serve it would display your own ad to 'fill the blank'.

Upvotes: 2

PravinCG
PravinCG

Reputation: 7708

Just to confirm does your adView has this as height parameter?

android:layout_height="wrap_content"

Upvotes: 2

Related Questions