letmetry7
letmetry7

Reputation: 11

How to show Admob ad on bottom?

can You please tell me how to show admob ad on bottom of the screen? I tried a few methods but the ad keeps showing up on top of page. Here is the xml

<com.google.android.gms.ads.AdView
    android:layout_alignParentTop="true"
    android:id="@+id/adView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    ads:adUnitId="@string/ad_id"
    android:visibility="@string/ad_visibility"
    ads:adSize="BANNER"
    android:background="#463B39"/>

<GridView
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_list_margin"
    android:paddingRight="@dimen/activity_horizontal_list_margin"
    android:paddingTop="@dimen/activity_vertical_list_margin"
    android:paddingBottom="@dimen/activity_vertical_list_margin"
    android:divider="@null"
    android:clipToPadding="false"
    android:numColumns="2"
    android:verticalSpacing="0dp"
    android:horizontalSpacing="0dp"
    android:stretchMode="columnWidth">

</GridView>

Upvotes: 0

Views: 2596

Answers (1)

Libin
Libin

Reputation: 17095

You have to set the layout_alignParentBottom as true

Create a RelativeLayout as parent and place your GridView and AdView

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

<com.google.android.gms.ads.AdView
    android:layout_alignParentBottom="true"
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

<GridView
    android:id="@+id/listView"
    android:layout_above="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</GridView>

</RelativeLayout>

EDIT:

Another way using LinearLayout.Create a parent vertical LinearLayout and place your GridView at Top and AdView at Bottom.

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      xmlns:ads="http://schemas.android.com/apk/res-auto"
      android:orientation="vertical">

<GridView
  android:id="@+id/listView"
  android:layout_width="wrap_content"
  android:layout_height="match_parent"
  android:background="@color/Red"
  android:layout_weight="2"/>

<com.google.android.gms.ads.AdView
   android:id="@+id/welcomeAdView"
   android:layout_width="match_parent"
   android:layout_height="100dp"
   ads:adSize="SMART_BANNER"
   ads:adUnitId=""
   android:layout_weight="1"/>
</LinearLayout>

Upvotes: 2

Related Questions