Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Positioning admob advert to bottom of screen

Tags:

android

admob

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.

like image 410
Boardy Avatar asked Nov 30 '25 04:11

Boardy


1 Answers

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

like image 118
FoamyGuy Avatar answered Dec 01 '25 17:12

FoamyGuy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!