2012-03-19 72 views
1

我有一個TabLayout有一個ListView顯示爲意圖。我想在這個佈局中放置一個admob橫幅,但是它在我之前定義的列表的最後一項上覆蓋了ListActivity。我如何得到這個工作?Admob顯示在標籤佈局的列表視圖

發帖現在的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> 

回答

7

爲了讓AdView的佔用它自己的空間,而不是坐的其他內容上面,我通常使用一個RelativeLayout和粘性android:layout_alignParentBottom="true"到我的AdView和android:layout_above="@+id/adView"放到我的頂級內容視圖中。

+0

要更具體地回答您的問題,AdView會懸停在列表的底部,因爲您有兩個LinearLayout元素。 Android在大多數基本ViewParent對象內將這些內容相互疊加,這就是爲什麼廣告漂浮在列表中,而不是佔據空間。 Eric的RelativeLayout方法可以工作,但通過將AdView放入第一個LinearLayout中,然後將FrameLayout放入ScrollView中以製作可滾動元素,可以達到相同的效果。 – Hounshell 2012-03-21 07:21:54

+0

那確實解決了我的問題。非常感謝! – anhnt 2015-06-06 01:48:23