1

I want to implement the ads in my app but I want to implement the ads on an overlay view, The main content of the app should be foreground and the overlay is top of the main content and I want to align the overaly at the bottom of the screen. Kindly tell me how I can achieve the overlay at the bottom of my screen???

Me Malik
  • 409
  • 2
  • 5
  • 13
  • 2
    What have you tried uptill now ? Please post code you have tried. – GrIsHu Oct 02 '13 at 04:36
  • I didn't do any thing. I have to start that.If I want to make it more clear then what I want to do is an overlay at the bottom of screen. if you have some code then let me know – Me Malik Oct 02 '13 at 05:00

1 Answers1

1

The simplest way to achieve this is to use a FrameLayout as your root view. Here is some code to demonstrate this. I haven't tested this particular example, but it should work with slight modification to the AdView attributes.

<FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
    <LinearLayout
        android:id="@+id/main_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <!-- Your main layout code goes here -->
    </LinearLayout>
    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        ads:adUnitId="MY_AD_UNIT_ID"
        ads:adSize="BANNER"
        ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
        ads:loadAdOnCreate="true"/>
</FrameLayout>

Note the layout_gravity attribute of the AdView; that's what causes it to appear at the bottom of the screen.

sampullman
  • 176
  • 1
  • 3
  • I'm not sure what exactly what you mean. The linear layout with id=main_layout will cover the whole screen, and the ad will show on the bottom on top of main_layout. Sanket's answer also presents a valid way of setting up overlays, but I've always found this one easier to understand for such a simple case. – sampullman Oct 02 '13 at 08:35