广告已完成加载,但未显示横幅广告(AdMob横幅广告)

时间:2017-05-15 10:04:50

标签: android admob banner

尝试了几种不同的方法,包括Listeners / Creating Linear Layout,但是根本没有显示banner(也尝试使用测试设备和模拟器)。 任何人都有这个解决方案?

这是MainActivity代码:

MainActivity.java
    public class MainActivity extends AppCompatActivity   {

        private GoogleApiClient client;
        private AdView adView;

        @Override
        public void onBackPressed() {
            getSupportFragmentManager().popBackStackImmediate();
            super.onBackPressed();
            int count = getSupportFragmentManager().getBackStackEntryCount();
            if (count == 0) {
                super.onBackPressed();
            }
            }

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            MobileAds.initialize(this, "pub-6338964718220230");
            AdView adView = (AdView) findViewById(R.id.adView);
            adView.setAdUnitId("ca-app-pub-6338964718220230/1764788102");
            adView.setAdSize(AdSize.SMART_BANNER);
            adView.setAdListener(new AdListener() {
                @Override
                public void onAdLoaded() {
                    Log.d("Ad", "onAdLoaded: ");
                }

                @Override
                public void onAdFailedToLoad(int errorCode) {
                    super.onAdFailedToLoad(errorCode);
                }
            });
            AdRequest adRequest = new AdRequest.Builder().addTestDevice("E1CDC038C238379BFAB16A576EC21D17").build();
            adView.loadAd(adRequest);

这是fragment_main xml代码:

fragment_main.xml

<com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:id="@+id/adView"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="ca-app-pub-6338964718220230/1764788102"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true">
</com.google.android.gms.ads.AdView>

这是activity_main xml代码:

activity_main.xml中

<com.google.android.gms.ads.AdView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/adView"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true">
    </com.google.android.gms.ads.AdView>

1 个答案:

答案 0 :(得分:0)

尝试将广告显示的大小更改为固定显示,以查看问题是否为adSize,我也遇到了类似问题,并且SMART_BANNER问题是