0

What I am trying to do is build a layout which if an AdMob Ad fails to load it shows one of my own Ads (ImageView) which are built into the app. I cant seem to get the listview not to cover up my Ad.

I have no issue getting it to work if I just use the AdMob Ad alone.

enter image description here

Here is my layout.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="fill_parent"
android:background="@drawable/bgdark"
android:orientation="vertical" >

<RelativeLayout
    android:id="@+id/actionbarLayout"
    android:layout_width="fill_parent"
    android:layout_height="@dimen/actionbar_height"
    android:layout_alignParentTop="true"
    android:layout_marginBottom="2dip"
    android:background="@drawable/actionbar_background" >

    //Top bar is here

</RelativeLayout>

<LinearLayout
    android:id="@+id/layoutAds"
    android:layout_width="match_parent"
    android:layout_height="50dip"
    android:background="#00FF00"
    android:layout_alignParentBottom="true"
    android:layout_centerVertical="true" >

    <ImageView
        android:id="@+id/ImageAlternativeAd"
        android:layout_width="wrap_content"
        android:layout_height="50dip"
        android:layout_gravity="center_vertical"
        android:src="@drawable/anad"
        android:visibility="visible" >
    </ImageView>

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        ads:adSize="BANNER"
        ads:adUnitId="123456abcd"
        ads:loadAdOnCreate="true"
        ads:testDevices="TEST_EMULATOR,CFFFFFFF9A836FD749F3EF439CD"
        android:visibility="visible" />
</LinearLayout>

<ListView
    android:id="@+id/listCategories"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@id/adView"
    android:layout_below="@id/actionbarLayout"
    android:cacheColorHint="#00000000" >
</ListView>

mbwasi
  • 3,612
  • 3
  • 30
  • 36
  • see if this link may help you http://stackoverflow.com/questions/5878283/android-admob-not-showing-linearlayout-on-bottom – kosa Jan 17 '12 at 18:36
  • @thinksteep That doesn't help I think, I cant use layout_weight since I have a RelativeLayout I fear changing to a LinearLayout would be a huge pain, might consider it if all else fails. – mbwasi Jan 17 '12 at 18:57

2 Answers2

0

I think a clean way to implement this would be to have a component that initially holds your com.google.ads.AdView view. Then, when you notice that your ad did not load, you can swap it with your ImageView on the fly.

Even better: make that a custom component. So from the "outside" (your layout) you are just including an instance of this component and internally, this component is implemented by either displaying an ad from AdMob or your own ad depending on whether the AdMob ad fails to load or not.

Bruno Oliveira
  • 5,056
  • 18
  • 24
0

This is exactly what you want.
https://stackoverflow.com/a/5188181/563306

Also, did you try with,

<ListView
    android:id="@+id/listCategories"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@id/layoutAds"
    android:layout_below="@id/actionbarLayout"
    android:cacheColorHint="#00000000" >
</ListView>
Community
  • 1
  • 1
dcanh121
  • 4,665
  • 11
  • 37
  • 84
  • Thanks, your layout works great was setting its layout_bellow the wrong thing. I'm controlling the visibility in the AdMob onReceivedAd and onFailedToReceiveAd and its working great. – mbwasi Jan 18 '12 at 10:06