rahul
rahul

Reputation: 6487

Android: admob ad at wrong place

I am trying to position my ad banner at bottom of the screen. However, part of the ad is appearing at the top and other part at the bottom. Please take a look at the image below

wrong ad http://img513.imageshack.us/img513/4390/shot000025.png

Below is the code if that helps,

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/maingradient"
    android:focusableInTouchMode="true"
    android:orientation="vertical" >

    <RelativeLayout
    android:id="@+id/relativelayout2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/relativeLayout1" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:cacheColorHint="@android:color/transparent"
        android:divider="#00ff00"
        android:fastScrollEnabled="true"
        android:focusable="false"
        android:listSelector="#000000"
        android:paddingTop="5dp"
        android:saveEnabled="true" >

    </ListView>
    </RelativeLayout>


    <com.google.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/adView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    ads:adSize="SMART_BANNER"
    android:layout_alignParentBottom="true"
    ads:adUnitId="a14fd64cddd4168"
    ads:loadAdOnCreate="true" />

</RelativeLayout>

Can someone help please?

Thx! Rahul.

Upvotes: 0

Views: 349

Answers (2)

moDev
moDev

Reputation: 5258

try the following code

 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="@android:color/black" >


<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="50dp"
ads:adSize="SMART_BANNER"
android:layout_alignParentBottom="true"
ads:adUnitId="a14fd64cddd4168"
ads:loadAdOnCreate="true" />


  <ListView
    android:id="@+id/show_locations_list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/black"
    android:layout_above="@+id/adView"
    android:scrollbars="none"
    android:scrollingCache="false" >
</ListView>

Hope it helps

Upvotes: 0

MattDavis
MattDavis

Reputation: 5178

Not sure what your exact problem is, but I see a few issues with your layout. First, you have a RelativeLayout nested inside another RelativeLayout, but are trying to place it below a third relative layout not contained in the parent? Also, the root RelativeLayout in your file has the android:orientation attribute, which is for LinearLayouts. It's all a bit confusing.

As for a solution, try making the root RelativeLayout a LinearLayout and keeping the vertical orientation. You can give your nested RelativeLayout a android:layout_height of 0dip and android:layout_weight of 1 (and get rid of the layout_below attribute, I'm not sure why it's there). This will put your ListView above the ad, and cause it to fill all the space not taken up by the Ad. Hope this helps.

Upvotes: 1

Related Questions