简体   繁体   English

只有在onResume上才能看到Admob视图

[英]Admob view is not visible until onResume

AdMob view is not visible, but clickable. AdMob视图不可见,但可以单击。 If call onResume() view become visible. 如果调用onResume(),则视图变为可见。 When I use AdMob library all work fine, but if use google play services for AdMob I got this issue. 当我使用AdMob库时,一切正常,但是如果为AdMob使用Google Play服务,则会出现此问题。 My code is bellow. 我的代码在下面。

   protected void initAdMob(){
      if (mAdView == null) {
         mAdView = new AdView(MainActivity.this);
         mAdView.setAdUnitId(getString(R.string.admob_id));
         mAdView.setAdSize(AdSize.SMART_BANNER);
         mAdView.loadAd(new AdRequest.Builder().build());
         mAdView.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
              super.onAdClosed();
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
              super.onAdFailedToLoad(errorCode);
            }

            @Override
            public void onAdLeftApplication() {
              super.onAdLeftApplication();
            }

            @Override
            public void onAdOpened() {
              super.onAdOpened();
            }

            @Override
            public void onAdLoaded() {
              super.onAdLoaded();
            }
         });
       }
    }

    private void showAdMob() {
      initAdMob();
     FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(                                                                                     FrameLayout.LayoutParams.MATCH_PARENT,                                         FrameLayout.LayoutParams.WRAP_CONTENT);
     params.gravity = Gravity.CENTER_HORIZONTAL;
     mAdView.setLayoutParams(params);

     FrameLayout fl = (FrameLayout) mainView.findViewById(R.id.adView);
     if (fl != null) {
        fl.removeAllViews();
        fl.addView(mAdView, params);
     }
   }



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

view xml: 查看xml:

    <FrameLayout
            android:id="@+id/gameLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

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

</RelativeLayout>

需要在AdMob中使用中介ID而不是发布者ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM