繁体   English   中英

无法将广告放置在线性布局的底部

[英]Unable to place the ad at bottom of linear layout

我试图将广告永久放置在布局的底部。 我使用的是tabhost,当我将广告放置在freamelayout上方时,它会在顶部显示广告。 我想将此广告放在底部。 这是我的布局文件的代码。

<?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"
    android:background="@drawable/background_splash"
    >
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <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="match_parent"
            />
            <com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="480dp"
                         android:layout_height="100dp"
                         ads:adUnitId="XXXXXXXXX"
                         ads:adSize="BANNER"
                         ads:testDevices="TEST_EMULATOR, XXXXXXXX"
                         ads:loadAdOnCreate="true"/>

        </LinearLayout>
</TabHost>

当我将adview放在框架布局之前时,它会向我显示广告,但我想在tabhost的底部显示广告。

谢谢阿曼

问题在于,FrameLayout的高度设置为match_parent。

您需要做的是,将FrameLayout的layout_height设置为0dip,然后将layout_weight设置为1。这将指示它填充空间。

试试这个代码:

<?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"
    android:background="@drawable/background_splash">
   <LinearLayout
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
    <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="0dp"
        android:layout_weight="1"
        />
        <com.google.ads.AdView android:id="@+id/adView"
                     android:layout_width="480dp"
                     android:layout_height="100dp"
                     ads:adUnitId="a15131e8f06efd9"
                     ads:adSize="BANNER"
                     ads:testDevices="TEST_EMULATOR, XXXXXXXX"
                     ads:loadAdOnCreate="true"/>

    </LinearLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM