Reputation: 347
Once more I need some help. Trial and error is not working so well. Can someone please look at my code? I want my listview to contain admob ads at the top of the page and I am struggling a bit this morning. Thanks in advance!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp"
>
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxxxxxxxx"
ads:loadAdOnCreate="true"
android:layout_alignParentTop="true" />
<TextView
android:id="@+id/txtPlaceName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:ellipsize="end"
android:singleLine="true"
android:text="saa"
android:textSize="25sp"
android:layout_below="@id/adView" />
<LinearLayout
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imgType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/marker1" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/txtCityState"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="city, st"
android:textSize="15sp" />
<TextView
android:id="@+id/txtDistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textSize="15sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RatingBar
android:id="@+id/average_ratingbar"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:numStars="5"
android:stepSize="1.0" />
<TextView
android:id="@+id/txtCommentsCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textSize="15sp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Upvotes: 0
Views: 746
Reputation: 8931
Short answer
The Banner ad needs 320dp width. Your base LinearLayout has android:padding="5dp"
so you only have 310dp left, and the ad therefore doesn't fit on the screen.
For the future
Android has a logging tool called LogCat that keeps track of all messages that are logged. AdMob SDK provides logging messages that can be very helpful when debugging these issues. This is how I was able to solve your problem.
You can view the LogCat output using the command line by following the directions from the link provided above, or you can view the LogCat output in Eclipse by going to Window -> Show View -> LogCat
. When requesting an ad, the SDK logged the following message:
Not enough space to show the ad! Wants: <320,50>, Has: <310,473>
From there it was pretty easy to tell that you didn't have the full 320 width, and sure enough your top level layout had 5dp padding on each side.
Unrelated Layout Tip
Fyi, the android:layout_alignParentTop
and android:layout_below
attributes only do anything inside of a RelativeLayout. In the layout you provided above, these attributes on the AdView and the TextView don't do anything.
Upvotes: 1