Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Admob size does not fill parent

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...

like image 375
alessiop86 Avatar asked Dec 30 '13 10:12

alessiop86


2 Answers

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.

like image 89
Szymon Avatar answered Sep 21 '22 10:09

Szymon


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>
like image 44
Zohab Ali Avatar answered Sep 23 '22 10:09

Zohab Ali