Callum
Callum

Reputation: 51

Put ads at the bottom of the page, android

I am using the admob service which google provides to enable the developer to put ad's into their app. The app is displaying fine, however I want the app to appear at the bottom of the screen, as opposed to the top.

Given my below XML code, how would I do this?

Thanks for any help!

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout android:layout_alignParentTop="true"
         android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
        >
    <android.support.v4.view.ViewPager
    android:id="@+android:id/viewpager"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />
    </LinearLayout>
      <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"        
        ads:adSize="SMART_BANNER"
        ads:adUnitId="" >

    </com.google.android.gms.ads.AdView>


</RelativeLayout>

I am also using this java code:

 adView = (AdView) this.findViewById(R.id.adView);
        // Create an ad.
        adView = new AdView(this);
        adView.setAdSize(AdSize.SMART_BANNER);
        adView.setAdUnitId(AD_UNIT_ID);

        //LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
        RelativeLayout layout = (RelativeLayout) findViewById(R.id.linearLayout);
        layout.addView(adView);

        AdRequest adRequest = new AdRequest.Builder()
        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
        .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
        .build();

Upvotes: 0

Views: 896

Answers (2)

Psypher
Psypher

Reputation: 10839

In your Adview add the line android:layout_alignParentBottom="true" to display it in bottom of the parent and also your linear layout is taking up entire screen space change the height to wrap content.

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:orientation="vertical">

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="" />
</RelativeLayout>

Upvotes: 1

Litrik De Roy
Litrik De Roy

Reputation: 1032

Try this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:ads="http://schemas.android.com/apk/res-auto"
  android:id="@+id/linearLayout"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">

  <android.support.v4.view.ViewPager
  android:id="@+android:id/viewpager"
  android:layout_width="match_parent"
  android:layout_height="0dp"
  android:layout_weight="1"
  />

<com.google.android.gms.ads.AdView
  android:id="@+id/adView"
  android:layout_width="match_parent"
  android:layout_height="50dp"        
  ads:adSize="SMART_BANNER"
  ads:adUnitId="" />

</LinearLayout>

Upvotes: 0

Related Questions