每个选项卡上的 adview(tabhost、admob)

发布于 2025-01-07 13:21:48 字数 3641 浏览 2 评论 0原文

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

主要.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>

Im trying to get the Google Ads adview on every tab of my tabhost, but its not working.
If I place the adview in the main.xml, I can see the adview on every tab.
But the problem then is that the views (buttons) are showing above the adview, so I cant see the ad anymore?

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗弃M 2025-01-14 13:21:48

让我们尝试一下这个布局。它始终位于框架布局下方。希望它有帮助。

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

Lets try this layout.It is always below the frame layout.Hope it helps.

<?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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文