Problem with admob position

I have an app with a landscape mode that i cant manage to place the admob view in the top of the screen


i want it to be placed on top of all the views, as you can see in the image it does not occupy the whole width of the screen here is my xml code

<?xml version="1.0" encoding="utf-8"?>
<!--
 Copyright (C) 2010 Peter Dornbach.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
--> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:coloring="http://schemas.android.com/apk/res/com.andnottech.talwen"
              
              android:orientation="horizontal"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent" >


     
    
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="vertical"
                  android:layout_width="wrap_content"
                  android:layout_height="fill_parent"
                                           > 
                  
                                          
        
                  
        <!-- The colors used here should match one of the colors in pick_color.xml -->
        <com.andnottech.talwen.widget.ColorButton android:layout_width="wrap_content"
                                         android:layout_height="wrap_content"
                                         coloring:color="#FF0000"/>
        <com.andnottech.talwen.widget.ColorButton android:layout_width="wrap_content"
                                         android:layout_height="wrap_content"
                                         coloring:color="#FFA500"/>
        <com.andnottech.talwen.widget.ColorButton android:layout_width="wrap_content"
                                         android:layout_height="wrap_content"
                                         coloring:color="#FFFF00"/>
        <com.andnottech.talwen.widget.ColorButton android:layout_width="wrap_content"
                                         android:layout_height="wrap_content"
                                         coloring:color="#32CD32"/>
        <com.andnottech.talwen.widget.ColorButton android:layout_width="wrap_content"
                                         android:layout_height="wrap_content"
                                         coloring:color="#0000FF"/>
        <com.andnottech.talwen.widget.ColorButton android:layout_width="wrap_content"
                                         android:layout_height="wrap_content"
                                         coloring:color="#800080"/>
        <com.andnottech.talwen.widget.ColoringImageButton android:id="@+id/pick_color_button"
                                         android:layout_width="wrap_content"
                                         android:layout_height="wrap_content"/>
    </LinearLayout>
	    
           

              
    
    
    
    
    

    <LinearLayout android:orientation="vertical"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:gravity="center"
                 >
        
    
        <LinearLayout 
                  android:orientation="vertical"
    
                        android:layout_width="320dp" 
                        android:layout_height="50dp"
                         > 
<com.google.ads.AdView android:id="@+id/adview" 
                         android:layout_width="wrap_content" 
                         android:layout_height="wrap_content" 
                         ads:adUnitId="xxxxxxxxxxx" 
                         ads:adSize="BANNER"/> 

                  
</LinearLayout> 
                  
	    <com.andnottech.talwen.widget.PaintView android:id="@+id/paint_view"
	                                   android:layout_width="fill_parent" 
	                                   android:layout_height="fill_parent"
	                                    />
	    <ProgressBar android:id="@+id/paint_progress"
	                 style="?android:attr/progressBarStyleHorizontal"
	                 android:layout_width="240dip"
	                 android:layout_height="wrap_content" />
	    
	    
	    
	    
	    
	</LinearLayout>
	
    
    
	    
	    
    
</LinearLayout>

First of all I think that in AdView you want to use SMART_BANNER, instead of BANNER to have banner that uses all width (look at https://developers.google.com/mobile-ads-sdk/docs/admob/smart-banners ).

Second: I think that android:layout_width=“320dp” android:layout_height=“50dp” that is parent of your adview will be problem. I wouldn’t use linearlayout, better put AdView in relative layout, set align to top, width to match_parent and height to wrap_content.

I prefer adding adview via code:


adView = new AdView(activity, AdSize.SMART_BANNER, "your app ad id");

// lay into which I insert adview
RelativeLayout lay = (RelativeLayout) findViewById(relLayId);
RelativeLayout.LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
lay.addView(adView, lp);

AdRequest request = new AdRequest();

// do something with request, change location etc.

adView.loadAd(request);