Adding AdView below TabHost in XML
Asked Answered
S

1

2

I am trying to get an AdView directly below a TabHost. RelativeLayout does allow this to happen with android:layout_alignParentBottom="true" however this overlaps TabHost contents, and does so for the ScrollView's I add inside each Tab (this would probably occur for any views whose height was large enough)

Right now the closest I can get to having a TabHost and AdView in their own seperate space on the screen is using this code (below), that allows me to have a Ad directly above the TabHost...so close, any ideas?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <com.google.ads.AdView
        android:id="@+id/ad"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="####"
        ads:loadAdOnCreate="true"
        ads:testDevices="####" />

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

            <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="fill_parent" />
        </LinearLayout>
    </TabHost>

</LinearLayout>

Spinous answered 21/12, 2011 at 0:47 Comment(0)
S
4

You should make the tab host to fill the remaining space after the adview like

<TabHost
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="0dip" 
    android:layout_weight="1.0">

Now the tab host will take the remaining space after the adview.

Schmaltz answered 21/12, 2011 at 2:19 Comment(1)
Thank you! This worked as soon as I did this and put the adview below the tabhost in the xml :)Spinous

© 2022 - 2024 — McMap. All rights reserved.