每个标签上的广告查看(tabhost,admob)

时间:2012-02-20 17:42:58

标签: java android admob adview

我试图在adview的每个标签上获取Google广告tabhost,但它无效。 如果我将广告视图放在main.xml中,我可以在每个标签上看到广告视图。 但问题是视图(按钮)显示在广告视图上方,所以我再也看不到该广告了?

main.xml中:

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

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

        <TabHost
            xmlns:android="http://schemas.android.com/apk/res/android"
            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: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" >

                    <include layout="@layout/tab1" />

                    <include layout="@layout/tab2" />

                    <include layout="@layout/tab3" />

                    <include layout="@layout/tab4" />
                </FrameLayout>
            </LinearLayout>
        </TabHost>
    </TableLayout>
</LinearLayout>

tab1.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res/com.this.app"
    android:id="@+id/tab1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="xxx" />

    <ScrollView
        android:id="@+id/scrollview1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@id/adView" >

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

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

                <TableRow>

                    <Button
                        android:id="@+id/button1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="1" />

                    <Button
                        android:id="@+id/button2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="2" />
                </TableRow>
            </TableLayout>
        </LinearLayout>
    </ScrollView>

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

让我们试试这个布局。它始终低于框架布局。希望它有所帮助。

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#fff" >

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

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@+id/tv"
            android:layout_below="@android:id/tabs" >
        </FrameLayout>

        <TextView
            android:id="@+id/tv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:text="Ads" />

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@android:id/tabcontent"
            android:layout_alignParentTop="true"
            android:paddingTop="-10dip" >
        </TabWidget>
    </RelativeLayout>

</TabHost>