怎么使用 CoordinatorLayout 将 admob 横幅放在屏幕底部

本教程将介绍如何使用 CoordinatorLayout 将 admob 横幅放在屏幕底部的处理方法,这篇教程是从别的地方看到的,然后加了一些国外程序员的疑问与解答,希望能对你有所帮助,好了,下面开始学习吧。

怎么使用 CoordinatorLayout 将 admob 横幅放在屏幕底部 教程 第1张

问题描述

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>

解决方案

try below mechanism.Put your viewpager and AdView inside
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 横幅放在屏幕底部的教程就到这里就结束了,希望趣模板源码网找到的这篇技术文章能帮助到大家,更多技术教程可以在站内搜索。