Admob showing over a listview in tab layout

2020-07-30 02:54发布

问题:

i have a TabLayout that has a ListView to show as intent. I would like to put an admob banner in this layout, but it goes over the ListActivity, over the last item of the list i defined before. How can i get this working?

Posting now the main.xml:

<?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">

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="top"
    android:orientation="vertical"
    android:padding="5dp" >

    <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"
        android:padding="5dp" >

    </FrameLayout>

</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:gravity="bottom" >

<com.google.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"

            ads:adSize="BANNER"
            ads:adUnitId="a14f67193b8a3e1"
            ads:loadAdOnCreate="true"
            ads:testDevices="TEST_EMULATOR, 3433B134225900EC" >

        </com.google.ads.AdView>
 </LinearLayout>

回答1:

To get the AdView to take up it's own space and not sit on top of other content, I usually use a RelativeLayout and tack android:layout_alignParentBottom="true" onto my AdView and android:layout_above="@+id/adView" onto my top level content view.