android - Admob 广告不显示在带有 fragment 线性布局的选项卡中

标签 android admob android-linearlayout

我正在尝试在屏幕底部实现广告,有人告诉我必须将线性布局更改为 RelativeLayout 但是当我这样做时我的工具栏不知何故变得更小并且选项卡开始看起来很奇怪。所以我认为可能有是一些我需要更改或添加到我不知道的相对布局的东西这是我的线性布局在这里

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

   android:orientation="vertical"
   tools:context="com.example.Jus.Forever.MainActivity">

   <android.support.v7.widget.Toolbar
       android:id="@+id/toolbar"
       android:layout_width="match_parent"
       android:layout_height="?attr/actionBarSize"
       android:background="?attr/colorPrimary"/>

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

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

   <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_footer">
   </com.google.android.gms.ads.AdView>

</LinearLayout>

最佳答案

由于没有您想要的图像,我只能猜测。但这应该有效:

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

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"/>

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

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

    <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="12345">
    </com.google.android.gms.ads.AdView>

</RelativeLayout>

关于android - Admob 广告不显示在带有 fragment 线性布局的选项卡中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38381599/

相关文章:

java - Cipher.unwrap() key 长度 Sun - BouncyCaSTLe 兼容性

java - 光标似乎无法在 Android 应用程序中工作

java - 如何修复 ListView 中的 Admob 广告

Cordova 构建错误 : More than one library with package name 'com. google.android.gms

android - ListView 中自定义可检查元素的初始状态 "checked"

android - android 中的圆角菜单

安卓 9 : Background Restriction App Setting

android - 如何先按文本排序,然后按包含数字的文本排序

java - 在 Android Studio 中启动应用程序时加载插页式广告

android - 如何在android中的Relativelayout内底部放置一个Linearlayout