Android AdMob not showing LinearLayout on Bottom

JPM picture JPM · May 4, 2011 · Viewed 8.3k times · Source

Okay really weird situation with AdMob. I want to place the ad on the bottom I have a LinearLayout. When I do it never shows up. When I place it on top it shows up perfectly. Not sure what the deal is here is my code. I do get a warning in LogCat that says "Not enough space to show ad! Wants <480,75> Has: <480, 0>"

LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res/mypackage"
 android:id="@+id/mainmenulayout"
 android:orientation="vertical" 
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">

    <ImageView  android:id="@+id/headerpic"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/header"/>

    <ListView android:id="@android:id/list" 
    android:divider="#00000000" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:drawSelectorOnTop="false"
    android:background="@android:color/transparent"
    android:cacheColorHint="#00000000"
    android:layout_alignParentTop="true">
    </ListView>

    <com.google.ads.AdView 
      android:id="@+id/adView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      ads:adUnitId="myadunit"
      ads:adSize="BANNER"
    />
 </LinearLayout>

and my onCreate():

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.appmenu);

    // Look up the AdView as a resource and load a request.
    AdView adView = (AdView)this.findViewById(R.id.adView);
    adView.loadAd(new AdRequest());

    String[] mainMenuList = getResources().getStringArray(R.array.mainMenuList);
    TypedArray[] picFiles = getResources().obtainTypedArray(R.array.arrayIcon);

    setListAdapter(new MyIconAdapter(mainMenuList, picFiles));

    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

}  //close onCreate

Answer

Ted Hopp picture Ted Hopp · May 4, 2011

My guess is that your list view fills the screen and is pushing the adview down. Try this xml for the list view:

<ListView android:id="@android:id/list" 
    android:divider="#00000000" 
    android:layout_width="fill_parent"
    android:layout_height="0px" 
    android:layout_weight="1"
    android:drawSelectorOnTop="false"
    android:background="@android:color/transparent"
    android:cacheColorHint="#00000000"
    android:layout_alignParentTop="true">
    </ListView>

This will give the list view only as much real estate as is available after the image view and ad view claim their share.