如何使用CoordinatorLayout将admob横幅广告放到屏幕底部 [英] How to put admob banner to bottom of the screen using CoordinatorLayout

查看:111
本文介绍了如何使用CoordinatorLayout将admob横幅广告放到屏幕底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CoordinatorLayout在activity_main.xml文件中制作滑动选项卡. 我想将admob横幅广告放到屏幕底部.但是我有一个问题,当我尝试在下面进行编码时(activity_main.xml),Admob标语显示在屏幕顶部而不是屏幕底部.实际上,我认为此提示显示在工具栏的底部(如图所示).但我想显示整个屏幕

I use CoordinatorLayout to make sliding tabs in activity_main.xml file. I want to put admob banner to bottom of the screen. But I have a problem, When I try to code below(activity_main.xml) Admob banner is shown of the top of the screen not bottom of the screen. In fact, I think this admob is shown bottom of the Toolbar(Seen in the picture). But I want to show bottom of the whole screen

       <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:ads="http://schemas.android.com/tools"
        >

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

        </com.google.android.gms.ads.AdView>

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:tabMode="fixed"
                app:tabGravity="fill"/>

        </android.support.design.widget.AppBarLayout>

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"

            />

    </android.support.design.widget.CoordinatorLayout>

推荐答案

尝试以下机制,将viewpagerAdView放入 RelativeLayout.

这是示例布局文件.

here is the sample layout file.

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    </android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="?actionBarSize">

    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/view_pager"
       >

    </android.support.v4.view.ViewPager>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true">

    </com.google.android.gms.ads.AdView>
</RelativeLayout>

这篇关于如何使用CoordinatorLayout将admob横幅广告放到屏幕底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆