Admob 广告未显示在 Android 回收站视图中

Admob ads not showing in Android recycler view

你好,我的应用在 Android 回收站视图中没有显示广告 我想在我的应用底部显示广告,但它没有显示我不想显示原生广告 我只想在底部显示一个横幅。这是一个字典应用程序,它使用 Sqlite 数据库加载数据,原生广告不适合它。你能帮忙吗这是我的代码。 主要 activity.java

mAdView = (AdView) findViewById(R.id.adView);
mAdView.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded() {
        Toast.makeText(getApplicationContext(), "onAdFailedToLoad", Toast.LENGTH_LONG).show();
            if (mAdView.getVisibility() == View.GONE) {
                mAdView.setVisibility(View.VISIBLE);
            }
        }
        @Override
        public void onAdFailedToLoad(int errorCode) {
            Toast.makeText(getApplicationContext(), "onAdFailedToLoad", Toast.LENGTH_SHORT).show();
        }
        @Override
        public void onAdOpened() {
            Toast.makeText(getApplicationContext(), "onAdOpened", Toast.LENGTH_SHORT).show();
        }
        @Override
        public void onAdLeftApplication() {
            Toast.makeText(getApplicationContext(), "onAdLeftApplication", Toast.LENGTH_SHORT).show();
        }
        @Override
        public void onAdClosed() {
            Toast.makeText(getApplicationContext(), "onAdClosed", Toast.LENGTH_SHORT).show();
        }
    });


    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

这是我的内容main.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#e2e2e2"
    android:paddingBottom="10dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="10dp">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/adView"
        android:descendantFocusability="blocksDescendants"
        android:scrollbars="vertical"/>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111"/>
</RelativeLayout>

在 OnCreate 上添加

MobileAds.initialize(this,"Your ad unit id from admob");
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice("Add Your Device id").build();
mAdView.loadAd(adRequest);

覆盖方法

@Override
public void onPause() {
    if (mAdView != null) {
         mAdView.pause();
    }
    super.onPause();
}

@Override
public void onResume() {
    super.onResume();
    if (mAdView != null) {
         mAdView.resume();
    }
}

@Override
public void onDestroy() {
    if (mAdView != null) {
         mAdView.destroy();
    }
    super.onDestroy();
}

您的 XML 文件

<com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="10dp"
        android:layout_marginRight="10dp"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_home_footer" />