0

I am trying to integrate AdMob into my Android Application, and can get it to work fine in the simulator when using the default sample layout code to position AdMob at the bottom of the screen, however whenever I try to position it to the top of the screen no adverts get served. I have read that this could perhaps be due to lack of space for the adverts.

This code works at the bottom of the screen (portrait):

<RelativeLayout 
    android:id="@+id/InnerRelativeLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" >

   <com.admob.android.ads.AdView
      android:id="@+id/ad" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"
      app:backgroundColor="#000000"
      app:primaryTextColor="#FFFFFF"
      app:secondaryTextColor="#CCCCCC"
      android:layout_alignParentBottom="true"
    />

</RelativeLayout>

But when I try to position it at the top it does not work

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widget40"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.myapp.xxxx"
>

<RelativeLayout 
        android:id="@+id/InnerRelativeLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" >

       <com.admob.android.ads.AdView
          android:id="@+id/ad" 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content"
          app:backgroundColor="#000000"
          app:primaryTextColor="#FFFFFF"
          app:secondaryTextColor="#CCCCCC"
          android:layout_alignParentTop="true"
        />
    </RelativeLayout>

<TextView
    android:id="@+id/widget28"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Input Amount:"
    android:layout_marginLeft="10dip"
    android:layout_marginTop="10dip"
    android:layout_marginRight="10dip"
    android:textSize="16dip"
    android:textStyle="bold">
</TextView>

Any help would be appreciated.

Thanks Aaron

MonkeyBlue
  • 2,234
  • 6
  • 31
  • 41

2 Answers2

1

If you always want to display on top of the screen then you may want to consider using RelativeLayout.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<com.admob.android.ads.AdView
      android:id="@+id/ad" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"
      app:backgroundColor="#000000"
      app:primaryTextColor="#FFFFFF"
      app:secondaryTextColor="#CCCCCC"
      android:layout_alignParentTop="true"
    />

<!-- TextView below that -->

<TextView
android:id="@+id/widget28"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Input Amount:"
android:layout_marginLeft="10dip"
android:layout_marginTop="10dip"
android:layout_marginRight="10dip"
android:layout_below="@id/ad"
android:textSize="16dip"
android:textStyle="bold">
</TextView>

</RelativeLayout>
dcanh121
  • 4,665
  • 11
  • 37
  • 84
0

Make sure you are not scaling the emulator screen as this has caused me problems whereby the ads don't appear. I have also had to set the ads layout_height="50dip" to make sure the ads don't suddenly push the other Views (controls) down the screen and mess up the layout.

Caltor
  • 2,538
  • 1
  • 27
  • 55