2016-07-01 18 views
0

私のレイアウトにAdviewを追加しようとしました。インターネット接続がない場合は、空白が表示される点を除いて、正常に動作します。私がこれまで読んできたように、私はadmobの標準的な動作は、広告が表示されている場合にのみスペースを取ることであることを理解します。そうでなければ、例えば。インターネットに接続されていない場合、レイアウトスペースは必要ありません。私は、アプリのGradleで、その後、私は私がミスを犯したかもしれないと私は、この奇妙な動作が発生した理由だと思うのコード...AdmobのAdviewは、インターネットに接続していない場合は空白のボックスを表示します。

<LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     xmlns:ads="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:background="#FFFFFF" 
     android:weightSum="1"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     android:theme="@style/AppTheme.AppBarOverlay" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    <include layout="@layout/content_main" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 


    <com.google.android.gms.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     ads:adSize="BANNER" 
     ads:adUnitId="@string/banner_ad_unit_id"> 
    </com.google.android.gms.ads.AdView> 
</LinearLayout> 

をリストアップしています:

dependencies { 
compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:23.4.0' 
    compile 'com.android.support:design:23.4.0' 
    compile 'com.google.firebase:firebase-core:9.2.0' 
    compile 'com.google.firebase:firebase-ads:9.2.0' 
} 
apply plugin: 'com.google.gms.google-services' 

とモジュールのGradleで:

dependencies { 
    classpath 'com.android.tools.build:gradle:2.1.0' 
    classpath 'com.google.gms:google-services:3.0.0' 

私は間違ったことをしたと思いますので、アドバイスをお願いします。 ありがとうございました!

+0

ボックスは任意の境界線やそのちょうど空の領域を持っているにこのコードを追加しますか? – giannisf

+0

ボーダーなし、空白... – Rucsi

+1

インターネット接続のチェックと、利用できない場合は隠れていることを確認することをお勧めします。 – giannisf

答えて

6

は、あなたのクラスファイル

AdView adView = (AdView)findViewById(R.id.adView); 
    AdRequest adRequest = new AdRequest.Builder().build(); 
    adView.loadAd(adRequest); 
adView.setAdListener(new AdListener() { 
     @Override 
     public void onAdLoaded() { 
      super.onAdLoaded(); 
      adView.setVisibility(View.VISIBLE); 
     } 

     @Override 
     public void onAdFailedToLoad(int errorCode) { 
      super.onAdFailedToLoad(errorCode); 
      adView.setVisibility(View.GONE); 
     } 
    }); 
+0

あなたの問題は修正されているかどうか私の回答コードを使用して? –

+0

ありがとう、私はそれを試してみる...しかし、私は本当に欲しかったのは、私がこの行動を取る理由を知ることでした。誰にもこの空間を残すためにいつも起こっているのですか? ?...... – Rucsi

+0

はい、これはただ一つの解決策です。 –

関連する問題