我的广告没有展示

My ads are not showing

大家好... 我有应用程序的源代码 当我更改 admob 的代码时,我的广告没有展示。 有什么问题吗? enter image description here

据我所知,问题出在您的 XML 上。您有一个嵌套在 ConstraintLayout 中的 RelativeLayout。这绝不是一个好主意。 ConstraintLayout 的全部意义在于能够制作平面布局树,而不是嵌套布局。其次,我能看到的最大问题是您的 FrameLayout 的高度为 match_parent。这将与您的广告视图重叠,因此您的广告将永远不可见。

所以,我的建议是,首先删除相关布局,然后进行限制,使框架底部不会与您的广告重叠。我还将高度更改为 wrap_content,这样它将填满视图,但不会重叠。

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
    android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay"
            android:id="@+id/view">

            <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|snap"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

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

        <FrameLayout
            android:id="@+id/fragment1"
            android:layout_width="match_parent"                
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            app:layout_constraintBottom_toTopOf="@id/adView"/>

        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_gravity="center"
            ads:adSize="BANNER"
            ads:adUnitId="@string/admob_publisher_id" />
</android.support.design.widget.CoordinatorLayout>

我没有花时间填写所有限制条件(您必须自己完成一些!),但此限制条件将帮助您入门。了解约束的作用。它可以做出非常灵活的更好的布局。