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



嗨,我的应用没有在android recycler视图中显示广告,我想在我的应用程序的底部显示广告,但是它不显示它们,我不想显示本机广告我只想在底部显示一个横幅。它是一个使用SQLite数据库加载数据本机广告的字典应用程序不适合它。您能在这里提供帮助是我的代码吗?主要活动.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>

添加on ongreate>

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" />

相关内容

  • 没有找到相关文章

最新更新