FrameLayout下面的Admob Banner

时间:2016-09-19 12:08:12

标签: java android android-studio admob

我正在现有项目中创建一个admob横幅。在相对布局中,我调用了一个FrameLayout,并在admob banner的代码下面。但问题是Admob横幅显示在framelayout内容之上。

我的XML代码如下

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:ads="http://schemas.android.com/apk/res-auto">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolbar"/>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/banner_home_footer"
        ads:background="@color/theme_ads"
        android:layout_alignParentBottom="true">
    </com.google.android.gms.ads.AdView>

</RelativeLayout>

layout

根据admob政策,我们不应将广告置于内容之上。我该如何解决这个问题?

2 个答案:

答案 0 :(得分:4)

FrameLayout设置为AdView

以上
<FrameLayout
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/adView"
    android:layout_below="@id/toolbar"/>

答案 1 :(得分:0)

另一个RelativeLayout换行;

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/main"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >


        <RelativeLayout
        android:id="@+id/inner_rel"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" >

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar" />

        <FrameLayout
            android:id="@+id/fragment_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/toolbar"/>



    </RelativeLayout>

</LinearLayout>
    <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="@string/banner_home_footer"
            ads:background="@color/theme_ads"
            android:layout_alignParentBottom="true">
        </com.google.android.gms.ads.AdView>

    </RelativeLayout>