Amandeep Singh
Amandeep Singh

Reputation: 3840

Unable to place the ad at bottom of linear layout

I am trying to get the ads in the bottom of the layout permanently. I am using tabhost, when I place my ad above the freamelayout it displays me the ad at the top. I want to place this ad on the bottom. Here is code for my layout file.

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background_splash"
    >
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            />
            <com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="480dp"
                         android:layout_height="100dp"
                         ads:adUnitId="XXXXXXXXX"
                         ads:adSize="BANNER"
                         ads:testDevices="TEST_EMULATOR, XXXXXXXX"
                         ads:loadAdOnCreate="true"/>

        </LinearLayout>
</TabHost>

When I place the adview before the frame layout it shows me the ad but I want to display the ad at the bottom of tabhost.

Thanks, Aman

Upvotes: 0

Views: 129

Answers (2)

Emil Adz
Emil Adz

Reputation: 41099

Try this code:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background_splash">
   <LinearLayout
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        />
        <com.google.ads.AdView android:id="@+id/adView"
                     android:layout_width="480dp"
                     android:layout_height="100dp"
                     ads:adUnitId="a15131e8f06efd9"
                     ads:adSize="BANNER"
                     ads:testDevices="TEST_EMULATOR, XXXXXXXX"
                     ads:loadAdOnCreate="true"/>

    </LinearLayout>

Upvotes: 1

Knossos
Knossos

Reputation: 16038

The problem, is that the height of FrameLayout is set to match_parent.

What you need to do, is set layout_height of FrameLayout to 0dip, then assign a layout_weight of 1. That will instruct it to fill the space.

Upvotes: 2

Related Questions