8

I will post the code below, my issue is this, in the emulator (Genymotion Galaxy Nexus 4.2.2) the admob banner stretches and fill its parent:

enter image description here

In a real device (Galaxy Nexus 4.3) the admob banner does not fill the whole width of its parent, leaving two white stripes on the sides:

enter image description here

this is the layout:

<?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" >

    <WebView  
 android:id="@+id/webview"
 android:layout_width="fill_parent"
 android:layout_height="0px"
 android:layout_weight="1"/>

    <com.google.android.gms.ads.AdView android:id="@+id/adView"
                         android:layout_width="fill_parent"
                         android:layout_height="wrap_content"
                         ads:adUnitId="ca-app-pub-1470640527107044/6766749615"
                         ads:adSize="SMART_BANNER"/>

</LinearLayout>

and this is the onCreate of the activity:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);    
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);    
        setContentView(R.layout.activity_detail);


        ActionBar actionBar = getSupportActionBar();            
        actionBar.setDisplayHomeAsUpEnabled(true);

        WebView myWebView = (WebView) findViewById(R.id.webview);    
        WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);    
        Bundle b = getIntent().getExtras();
        url = b.getString("url");           
        myWebView.loadUrl(url);
        myWebView.setWebViewClient(new MyWebViewClient());


        // Initiate a generic request.
        AdRequest adRequest = new AdRequest.Builder().build();    
        adView = (AdView) findViewById(R.id.adView);
        adView.loadAd(adRequest);
    }

What am I doing wrong? I have examined it a lot but I can not figure it out...

Szymon
  • 42,577
  • 16
  • 96
  • 114
alessiop86
  • 1,285
  • 2
  • 19
  • 38

3 Answers3

4

The answer is on AdMob website (about smart banner size):

When an image ad won't take up the entire allotted space for the banner, we'll center the image and use a hexagonal textile filler (see image) to fill up the remaining space. Note that AdSense backfill ads will be centered and have "transparent" filler.

The second image has an AdSense ad and hence the filler is transparent.

Szymon
  • 42,577
  • 16
  • 96
  • 114
  • 1
    Correct answer but not the one I hoped for, should I build some workaround to put on background a different color or the lateral white stripes are present in many apps? – alessiop86 Dec 30 '13 at 11:38
  • Yes, you could put your `AdView` on a background. But it's really up to you, it's a design choice, not a development one. In my app I prefer to leave it as is. – Szymon Dec 30 '13 at 11:40
4

I was having same issue and then I change adSize to ads:adSize="SMART_BANNER" so this is how my AdView block look like in xml file.

<com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/banner_ad_unit_id">
    </com.google.android.gms.ads.AdView>
Zohab Ali
  • 8,426
  • 4
  • 55
  • 63
0

Be sure to use the newly introduced AdMob Adaptive Banners. They don't require adjustments on your side and they utilize all the width available.

Embed them into a FrameLayout like following

<FrameLayout
    android:id="@+id/adFragment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center|bottom" />
S. Gissel
  • 1,788
  • 2
  • 15
  • 32