Admob显示在标签布局的列表视图
问题描述:
我有一个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>
答
为了让AdView的占用它自己的空间,而不是坐的其他内容上面,我通常使用一个RelativeLayout
和粘性android:layout_alignParentBottom="true"
到我的AdView和android:layout_above="@+id/adView"
放到我的*内容视图中。
要更具体地回答您的问题,AdView会悬停在列表的底部,因为您有两个LinearLayout元素。 Android在大多数基本ViewParent对象内将这些内容相互叠加,这就是为什么广告漂浮在列表中,而不是占据空间。 Eric的RelativeLayout方法可以工作,但通过将AdView放入第一个LinearLayout中,然后将FrameLayout放入ScrollView中以制作可滚动元素,可以达到相同的效果。 – Hounshell 2012-03-21 07:21:54
那确实解决了我的问题。非常感谢! – anhnt 2015-06-06 01:48:23