Boardy
Boardy

Reputation: 36205

Positioning admob advert to bottom of screen

I am working on an android project and just downloaded the latest version of the admob sdk.

I am trying to position the ad at the bottom of the screen but nothing I try seems to work.

Below is the XML code for 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/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <TextView android:id="@+id/password_noRecords"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_gravity="center"
        android:text="There are currently\nno saved logins"
        android:textSize="20dp"
        android:textStyle="bold|italic"/>
    <ListView 
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    </ListView>
        <com.google.ads.AdView android:id="@+id/adView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            ads:adUnitId="MY_ID"
            ads:adSize="BANNER"
            ads:testDevices="TEST_EMULATOR, emulator-5554"
            ads:loadAdOnCreate="true">
        </com.google.ads.AdView>
</LinearLayout>

I have tried making the ListView as well as the LinearLayout fill_parent on the height but then in the logcat is says that there's not enough room to display the ad.

I've also tried wrapping the ad in a linear layout and saying align parent bottom = true but that doesn't make a difference.

Instead the advert gets placed directly at the bottom of the list view, therefore if the list view is half empty the advert is in the middle of the screen.

What I want is the advert to always be visible at the bottom of the screen no matter how big or small the list view is.

Thanks for any help you can provide.

Upvotes: 2

Views: 6224

Answers (2)

PantOffl
PantOffl

Reputation: 1

Bro you might have to position the ad using the Design tab of the .xml file. Adjust the margins and such...

Upvotes: -2

FoamyGuy
FoamyGuy

Reputation: 46846

change your parent layout to a RelativeLayout

use android:layout_alignParentBottom="true" on the adView and android:layout_above="@+id/adView" on your ListView.

Use android:layout_below="@+id/xxxx" on the rest of your views as needed to make them behave the same as the do with your LinearLayout

Upvotes: 12

Related Questions