Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get ad to show at bottom of screen without overlap

I have an admob ad banner which I'd like to put at the bottom of my screen, and have the rest of the content resize to fill the available space when the ad loads in. I see the exact thing I want happen when I put the ad at the top of a linear layout and then have my content's height set to fill_parent. Is this possible to achieve in reverse? When I put my ad underneath my content with the fill_parent height, it doesn't show as there is not enough room. I have a solution with a relative layout and a margin on the bottom to save the space for the ad, but I don't like the black space that is there until the ad loads (if it does at all). Any ideas?

like image 708
Emma Assin Avatar asked Mar 21 '11 16:03

Emma Assin


1 Answers

You can do that by using RelativeLayout without doing hackish stuff:

<?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">
    <bla.bla.AdView
            android:id="@+id/ad"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="#FF0000"/>
    <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@id/ad"/>
</RelativeLayout>

If the ad does not load for some strange reason, the ListView will take all the available space. On the other hand, if the ad does load, the ListView won't be overlapped by the ad.

like image 131
Cristian Avatar answered Oct 07 '22 20:10

Cristian