[Android]将AdView添加到我的UI布局

时间:2016-11-29 13:12:16

标签: android android-layout adview

我的活动布局很复杂,如下所示:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">


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

    <LinearLayout
        android:id="@+id/container_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

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


    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/main_background">
        <android.support.v7.widget.GridLayout
            android:id="@+id/recycler"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:columnCount="2"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <FrameLayout
             app:layout_columnWeight="1"
             app:layout_rowWeight="1"
             android:background="@color/black_alpha_26">

            <TextView
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:gravity="center"
             android:text="YouTube"/>

    </FrameLayout>

    <FrameLayout
        app:layout_columnWeight="1"
        app:layout_rowWeight="1">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="Videos"/>

    </FrameLayout>

    <FrameLayout
        app:layout_columnWeight="1"
        app:layout_rowWeight="1">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="VR Apps"/>

    </FrameLayout>

    <FrameLayout
        app:layout_columnWeight="1"
        app:layout_rowWeight="1"
        android:background="@color/black_alpha_26">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="VR Movies"/>

    </FrameLayout>

    <FrameLayout
        app:layout_columnWeight="1"
        app:layout_rowWeight="1"
        android:background="@color/black_alpha_26">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="VR Games"/>

    </FrameLayout>

    <FrameLayout
        app:layout_columnWeight="1"
        app:layout_rowWeight="1">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="Shop"/>

    </FrameLayout>
            </FrameLayout>

        </android.support.v7.widget.GridLayout>
    </FrameLayout>
<!-Added the Adview here-->
</LinearLayout>
<android.support.v7.widget.RecyclerView
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:id="@+id/recyclerView"
    android:scrollbars="vertical"
    android:background="#000000"
    android:choiceMode="singleChoice"
    android:divider="@android:color/darker_gray"
    android:layout_gravity="left"
    />

我的目标是在上面的用户界面中添加横幅广告,以便在我的GridLayout下方添加广告。我将以下代码添加到上面注释的部分

<com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_home_footer">
</com.google.android.gms.ads.AdView>

但是,我无法看到我的Adview。我应该在哪里添加AddView来实现我的目标?

提前致谢!

0 个答案:

没有答案